{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 03_Train_TransE_l2\n",
    "#\n",
    "# created by LuYF-Lemon-love <luyanfeng_nlp@qq.com> on February 25, 2023\n",
    "# updated by LuYF-Lemon-love <luyanfeng_nlp@qq.com> on February 25, 2023\n",
    "#\n",
    "# 该脚本展示了如何在 DRKG 上训练模型 (TransE_l2), 并利用网格搜索寻找到最优参数.\n",
    "#\n",
    "# 需要的包:\n",
    "#          torch\n",
    "#          dgl, version: 0.4.3\n",
    "#          dglke\n",
    "#          numpy\n",
    "#\n",
    "# 需要的文件:\n",
    "#          ./dataset\n",
    "#\n",
    "# 源教程链接: https://github.com/gnn4dr/DRKG/blob/master/embedding_analysis/Train_embeddings.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Training DRKG Using TransE_L2\n",
    "\n",
    "这个 notebook 展示了如何在 DRKG 上训练模型 (TransE_l2), 并利用网格搜索寻找到最优参数."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 导入需要的库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 网格搜索参数\n",
    "\n",
    "我们能使用 DGL-KE 命令训练 TransE_l2 模型, 关于如何使用 DGL-KE 的更多信息请参考 https://github.com/awslabs/dgl-ke.\n",
    "\n",
    "这里我们使用两个 GPU 训练模型."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: **6**, 12, 18\n",
    "\n",
    "- lr: **0.01**, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.196 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.43700391720484477\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.4369735319183441\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5477654470011591\n",
      "[proc 0][Train](20000/100000) average loss: 0.49238468206971886\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5474305108830333\n",
      "[proc 0][Train](20000/100000) average regularization: 0.017768079455684687\n",
      "[proc 0][Train] 20000 steps take 393.754 seconds\n",
      "[proc 0]sample: 65.719, forward: 160.845, backward: 64.947, update: 98.214\n",
      "[proc 1][Train](20000/100000) average loss: 0.49220202122628687\n",
      "[proc 1][Train](20000/100000) average regularization: 0.01776876331345304\n",
      "[proc 1][Train] 20000 steps take 393.751 seconds\n",
      "[proc 1]sample: 68.120, forward: 165.051, backward: 65.771, update: 86.850\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.39963990386724474\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3997608205467463\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5205527044728399\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5204870014727115\n",
      "[proc 1][Train](40000/100000) average loss: 0.4600963042348623\n",
      "[proc 1][Train](40000/100000) average regularization: 0.02260374285718426\n",
      "[proc 0][Train](40000/100000) average loss: 0.46012391107529405\n",
      "[proc 1][Train] 20000 steps take 401.424 seconds\n",
      "[proc 1]sample: 66.707, forward: 160.389, backward: 64.589, update: 83.151\n",
      "[proc 0][Train](40000/100000) average regularization: 0.022607342285383494\n",
      "[proc 0][Train] 20000 steps take 401.437 seconds\n",
      "[proc 0]sample: 66.567, forward: 159.211, backward: 67.632, update: 107.735\n",
      "[1]Valid average MRR: 0.27899980050080925\n",
      "[1]Valid average MR: 154.9540607529774\n",
      "[1]Valid average HITS@1: 0.19245252184097456\n",
      "[1]Valid average HITS@3: 0.30753726414130755\n",
      "[1]Valid average HITS@10: 0.4420184260879631\n",
      "[proc 1]validation take 351.852 seconds:\n",
      "[0]Valid average MRR: 0.2778251752175739\n",
      "[0]Valid average MR: 157.45221849975485\n",
      "[0]Valid average HITS@1: 0.19118047611265457\n",
      "[0]Valid average HITS@3: 0.3058948902326088\n",
      "[0]Valid average HITS@10: 0.44148349403497306\n",
      "[proc 0]validation take 362.990 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.39010985823720695\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.39028083503395317\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.508875124040246\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.508958292466402\n",
      "[proc 0][Train](60000/100000) average loss: 0.44957797944545747\n",
      "[proc 1][Train](60000/100000) average loss: 0.44953407538086176\n",
      "[proc 0][Train](60000/100000) average regularization: 0.024135443134885283\n",
      "[proc 1][Train](60000/100000) average regularization: 0.024136399639584125\n",
      "[proc 0][Train] 20000 steps take 750.732 seconds\n",
      "[proc 0]sample: 66.025, forward: 158.118, backward: 67.223, update: 96.089\n",
      "[proc 1][Train] 20000 steps take 750.741 seconds\n",
      "[proc 1]sample: 64.836, forward: 160.996, backward: 64.588, update: 79.633\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.3840668772101402\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3842691720589995\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.5011787191808224\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.5011642395108938\n",
      "[proc 1][Train](80000/100000) average loss: 0.4426227982640266\n",
      "[proc 0][Train](80000/100000) average loss: 0.4427167057663202\n",
      "[proc 1][Train](80000/100000) average regularization: 0.024960520605836065\n",
      "[proc 0][Train](80000/100000) average regularization: 0.02495684781745076\n",
      "[proc 1][Train] 20000 steps take 381.959 seconds\n",
      "[proc 1]sample: 66.494, forward: 162.826, backward: 65.232, update: 85.150\n",
      "[proc 0][Train] 20000 steps take 381.964 seconds\n",
      "[proc 0]sample: 65.695, forward: 158.030, backward: 64.250, update: 85.152\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3802570567131042\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.3800630277261138\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.49534709322601556\n",
      "[proc 0][Train](100000/100000) average loss: 0.43780207496881485\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4953881467163563\n",
      "[proc 0][Train](100000/100000) average regularization: 0.025482333703059704\n",
      "[proc 1][Train](100000/100000) average loss: 0.4377255872666836\n",
      "[proc 0][Train] 20000 steps take 383.086 seconds\n",
      "[proc 0]sample: 66.629, forward: 163.410, backward: 64.651, update: 86.393\n",
      "[proc 1][Train](100000/100000) average regularization: 0.025485083211865277\n",
      "[proc 1][Train] 20000 steps take 383.092 seconds\n",
      "[proc 1]sample: 64.882, forward: 161.755, backward: 63.998, update: 88.461\n",
      "[0]Valid average MRR: 0.3382910173602461\n",
      "[0]Valid average MR: 124.41254358010568\n",
      "[0]Valid average HITS@1: 0.2450257394999183\n",
      "[0]Valid average HITS@3: 0.37389687857493054\n",
      "[0]Valid average HITS@10: 0.5165263932015035\n",
      "[proc 0]validation take 335.111 seconds:\n",
      "[1]Valid average MRR: 0.33983934897084694\n",
      "[1]Valid average MR: 122.23542289438025\n",
      "[1]Valid average HITS@1: 0.24678088208257012\n",
      "[1]Valid average HITS@3: 0.3748884969732461\n",
      "[1]Valid average HITS@10: 0.5172787133061414\n",
      "[proc 1]validation take 346.320 seconds:\n",
      "proc 1 takes 2657.288 seconds\n",
      "proc 0 takes 2657.298 seconds\n",
      "training takes 2657.824785709381 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_0\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.33840887139833253\n",
      "Test average MR : 124.20327938062196\n",
      "Test average HITS@1 : 0.24572713592133844\n",
      "Test average HITS@3 : 0.3736985639091089\n",
      "Test average HITS@10 : 0.5150758901516441\n",
      "-----------------------------------------\n",
      "testing takes 336.782 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 6.0 --lr 0.01 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: **6**, 12, 18\n",
    "\n",
    "- lr: 0.01, **0.05**, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.149 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.37048686309817713\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.3705925311545841\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.47044731014072894\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.4708188439115882\n",
      "[proc 1][Train](20000/100000) average loss: 0.42046708652228115\n",
      "[proc 0][Train](20000/100000) average loss: 0.4207056874141097\n",
      "[proc 1][Train](20000/100000) average regularization: 0.02488835208570083\n",
      "[proc 1][Train] 20000 steps take 385.959 seconds\n",
      "[proc 1]sample: 66.046, forward: 167.922, backward: 65.428, update: 82.757\n",
      "[proc 0][Train](20000/100000) average regularization: 0.024884578422618098\n",
      "[proc 0][Train] 20000 steps take 385.982 seconds\n",
      "[proc 0]sample: 66.801, forward: 161.387, backward: 64.743, update: 86.922\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.35667638325095175\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3567841072902083\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.4450077996045351\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.4449903850749135\n",
      "[proc 1][Train](40000/100000) average loss: 0.40084209147542715\n",
      "[proc 0][Train](40000/100000) average loss: 0.4008872461721301\n",
      "[proc 1][Train](40000/100000) average regularization: 0.026039026357419788\n",
      "[proc 0][Train](40000/100000) average regularization: 0.02603626450262964\n",
      "[proc 1][Train] 20000 steps take 380.885 seconds\n",
      "[proc 1]sample: 66.483, forward: 165.322, backward: 65.508, update: 80.511\n",
      "[proc 0][Train] 20000 steps take 380.884 seconds\n",
      "[proc 0]sample: 66.552, forward: 155.622, backward: 63.771, update: 85.381\n",
      "[1]Valid average MRR: 0.4237996791184308\n",
      "[1]Valid average MR: 75.54643292454564\n",
      "[1]Valid average HITS@1: 0.3062196558556964\n",
      "[1]Valid average HITS@3: 0.4869192479759222\n",
      "[1]Valid average HITS@10: 0.6449164833817932\n",
      "[proc 1]validation take 357.259 seconds:\n",
      "[0]Valid average MRR: 0.42279975131560965\n",
      "[0]Valid average MR: 76.98861469739064\n",
      "[0]Valid average HITS@1: 0.3051288336874217\n",
      "[0]Valid average HITS@3: 0.4857343247807376\n",
      "[0]Valid average HITS@10: 0.6443454812877921\n",
      "[proc 0]validation take 374.888 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.35414199718385936\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.44031542483121155\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.35430511713624\n",
      "[proc 1][Train](60000/100000) average loss: 0.3972287109270692\n",
      "[proc 1][Train](60000/100000) average regularization: 0.0258160459427163\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.4403110807299614\n",
      "[proc 1][Train] 20000 steps take 748.778 seconds\n",
      "[proc 1]sample: 64.664, forward: 163.241, backward: 65.017, update: 78.902\n",
      "[proc 0][Train](60000/100000) average loss: 0.3973080990076065\n",
      "[proc 0][Train](60000/100000) average regularization: 0.025811140364035964\n",
      "[proc 0][Train] 20000 steps take 748.784 seconds\n",
      "[proc 0]sample: 64.862, forward: 153.162, backward: 62.752, update: 82.273\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.35300169898122546\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3531729481860995\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.43805694107562304\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.43815223200321196\n",
      "[proc 0][Train](80000/100000) average loss: 0.3956149446174502\n",
      "[proc 1][Train](80000/100000) average loss: 0.3955769655317068\n",
      "[proc 0][Train](80000/100000) average regularization: 0.02561878371145576\n",
      "[proc 1][Train](80000/100000) average regularization: 0.025621735733374954\n",
      "[proc 0][Train] 20000 steps take 379.327 seconds\n",
      "[proc 0]sample: 66.648, forward: 156.708, backward: 63.917, update: 84.215\n",
      "[proc 1][Train] 20000 steps take 379.338 seconds\n",
      "[proc 1]sample: 65.492, forward: 166.362, backward: 65.152, update: 79.309\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.35227131222635505\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3524579848468304\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4366316643938422\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.43683805237859485\n",
      "[proc 1][Train](100000/100000) average loss: 0.39445148839056493\n",
      "[proc 0][Train](100000/100000) average loss: 0.39464801852852105\n",
      "[proc 1][Train](100000/100000) average regularization: 0.025467573648504913\n",
      "[proc 0][Train](100000/100000) average regularization: 0.025463672055397183\n",
      "[proc 1][Train] 20000 steps take 381.365 seconds\n",
      "[proc 1]sample: 66.433, forward: 164.770, backward: 65.478, update: 81.137\n",
      "[proc 0][Train] 20000 steps take 381.370 seconds\n",
      "[proc 0]sample: 66.491, forward: 155.516, backward: 63.467, update: 85.074\n",
      "[0]Valid average MRR: 0.42796099959437905\n",
      "[0]Valid average MR: 73.70411831998693\n",
      "[0]Valid average HITS@1: 0.3085675764013728\n",
      "[0]Valid average HITS@3: 0.49333020101323743\n",
      "[0]Valid average HITS@10: 0.6526563436291333\n",
      "[proc 0]validation take 352.701 seconds:\n",
      "[1]Valid average MRR: 0.42917269431302585\n",
      "[1]Valid average MR: 72.27962575839082\n",
      "[1]Valid average HITS@1: 0.3095392116140191\n",
      "[1]Valid average HITS@3: 0.49522664905316055\n",
      "[1]Valid average HITS@10: 0.65324771716704\n",
      "[proc 1]validation take 355.189 seconds:\n",
      "proc 1 takes 2631.514 seconds\n",
      "proc 0 takes 2631.535 seconds\n",
      "training takes 2631.994131565094 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_1\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.4280070101052291\n",
      "Test average MR : 74.04899153598399\n",
      "Test average HITS@1 : 0.30888551448007245\n",
      "Test average HITS@3 : 0.49331662773991025\n",
      "Test average HITS@10 : 0.6512661977297644\n",
      "-----------------------------------------\n",
      "testing takes 367.256 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 6.0 --lr 0.05 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: **6**, 12, 18\n",
    "\n",
    "- lr: 0.01, 0.05, **0.1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.149 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.36472126909838987\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.3642358608250739\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.4526550485815853\n",
      "[proc 0][Train](20000/100000) average loss: 0.40868815891742705\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.45229317944683134\n",
      "[proc 0][Train](20000/100000) average regularization: 0.025505526893606793\n",
      "[proc 1][Train](20000/100000) average loss: 0.40826452018022535\n",
      "[proc 0][Train] 20000 steps take 390.058 seconds\n",
      "[proc 0]sample: 67.079, forward: 165.571, backward: 65.649, update: 88.077\n",
      "[proc 1][Train](20000/100000) average regularization: 0.02549370362416073\n",
      "[proc 1][Train] 20000 steps take 390.050 seconds\n",
      "[proc 1]sample: 66.462, forward: 168.375, backward: 64.815, update: 82.856\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.35320213089585306\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.35334353166818616\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.4370715223625302\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.43704864513725045\n",
      "[proc 1][Train](40000/100000) average loss: 0.39513682666271926\n",
      "[proc 0][Train](40000/100000) average loss: 0.3951960883289576\n",
      "[proc 1][Train](40000/100000) average regularization: 0.02530809962237254\n",
      "[proc 0][Train](40000/100000) average regularization: 0.025310924637969582\n",
      "[proc 1][Train] 20000 steps take 387.506 seconds\n",
      "[proc 1]sample: 67.884, forward: 167.947, backward: 66.888, update: 84.030\n",
      "[proc 0][Train] 20000 steps take 387.518 seconds\n",
      "[proc 0]sample: 65.688, forward: 161.128, backward: 63.970, update: 86.052\n",
      "[0]Valid average MRR: 0.4297810868974758\n",
      "[0]Valid average MR: 72.12627676090864\n",
      "[0]Valid average HITS@1: 0.30951067712589203\n",
      "[0]Valid average HITS@3: 0.49641826006428064\n",
      "[0]Valid average HITS@10: 0.6553324344936536\n",
      "[proc 0]validation take 328.467 seconds:\n",
      "[1]Valid average MRR: 0.43042803551258113\n",
      "[1]Valid average MR: 70.89310689990944\n",
      "[1]Valid average HITS@1: 0.31025759752684584\n",
      "[1]Valid average HITS@3: 0.4966395881708056\n",
      "[1]Valid average HITS@10: 0.6553824468700845\n",
      "[proc 1]validation take 355.458 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.3522890993505716\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.35212309502363204\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.43512393071204425\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.4351553648114204\n",
      "[proc 0][Train](60000/100000) average loss: 0.39370651512742044\n",
      "[proc 0][Train](60000/100000) average regularization: 0.025007235088571906\n",
      "[proc 1][Train](60000/100000) average loss: 0.39363922993689776\n",
      "[proc 0][Train] 20000 steps take 733.856 seconds\n",
      "[proc 0]sample: 65.426, forward: 162.254, backward: 64.908, update: 83.652\n",
      "[proc 1][Train](60000/100000) average regularization: 0.025005064835213125\n",
      "[proc 1][Train] 20000 steps take 733.862 seconds\n",
      "[proc 1]sample: 64.938, forward: 163.610, backward: 64.792, update: 79.952\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3518436114490032\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4343129416659474\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.3516808095693588\n",
      "[proc 0][Train](80000/100000) average loss: 0.39307827664017675\n",
      "[proc 0][Train](80000/100000) average regularization: 0.024830901627708228\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4341656013160944\n",
      "[proc 0][Train] 20000 steps take 376.177 seconds\n",
      "[proc 0]sample: 65.245, forward: 163.235, backward: 64.363, update: 82.734\n",
      "[proc 1][Train](80000/100000) average loss: 0.39292320546209814\n",
      "[proc 1][Train](80000/100000) average regularization: 0.024829131898656487\n",
      "[proc 1][Train] 20000 steps take 376.183 seconds\n",
      "[proc 1]sample: 64.569, forward: 164.599, backward: 64.950, update: 79.271\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.351421559548378\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3515647487297654\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.43379541306495667\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4336756805688143\n",
      "[proc 0][Train](100000/100000) average loss: 0.39268008088320494\n",
      "[proc 0][Train](100000/100000) average regularization: 0.02471301218215376\n",
      "[proc 1][Train](100000/100000) average loss: 0.3925486201733351\n",
      "[proc 0][Train] 20000 steps take 385.165 seconds\n",
      "[proc 0]sample: 65.997, forward: 162.402, backward: 64.693, update: 86.463\n",
      "[proc 1][Train](100000/100000) average regularization: 0.02471118537914008\n",
      "[proc 1][Train] 20000 steps take 385.160 seconds\n",
      "[proc 1]sample: 66.607, forward: 167.373, backward: 65.657, update: 81.461\n",
      "[0]Valid average MRR: 0.430608388334019\n",
      "[0]Valid average MR: 70.76222966715694\n",
      "[0]Valid average HITS@1: 0.30926553903143217\n",
      "[0]Valid average HITS@3: 0.4976677834068748\n",
      "[0]Valid average HITS@10: 0.658447731110748\n",
      "[proc 0]validation take 313.758 seconds:\n",
      "[1]Valid average MRR: 0.43204861476570494\n",
      "[1]Valid average MR: 69.52074807465766\n",
      "[1]Valid average HITS@1: 0.3109487460590915\n",
      "[1]Valid average HITS@3: 0.4996901747958899\n",
      "[1]Valid average HITS@10: 0.6588654269118939\n",
      "[proc 1]validation take 319.200 seconds:\n",
      "proc 1 takes 2591.961 seconds\n",
      "proc 0 takes 2591.979 seconds\n",
      "training takes 2592.4821050167084 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_2\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.4307904352629973\n",
      "Test average MR : 71.29248861137025\n",
      "Test average HITS@1 : 0.310034591473338\n",
      "Test average HITS@3 : 0.49780398619064803\n",
      "Test average HITS@10 : 0.657181816324724\n",
      "-----------------------------------------\n",
      "testing takes 337.684 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 6.0 --lr 0.1 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: 6, **12**, 18\n",
    "\n",
    "- lr: **0.01**, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.108 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.48306862513065424\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.48317096809046345\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5908025254458189\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5919412916511297\n",
      "[proc 1][Train](20000/100000) average loss: 0.5369355750441551\n",
      "[proc 0][Train](20000/100000) average loss: 0.5375561297744512\n",
      "[proc 1][Train](20000/100000) average regularization: 0.0707572243387076\n",
      "[proc 0][Train](20000/100000) average regularization: 0.07078503617417037\n",
      "[proc 1][Train] 20000 steps take 394.662 seconds\n",
      "[proc 1]sample: 66.486, forward: 170.250, backward: 69.000, update: 84.682\n",
      "[proc 0][Train] 20000 steps take 394.668 seconds\n",
      "[proc 0]sample: 66.084, forward: 166.392, backward: 67.873, update: 87.559\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.4127023767948151\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.4130031098753214\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5464064779981971\n",
      "[proc 1][Train](40000/100000) average loss: 0.4795544273853302\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5462981368005275\n",
      "[proc 1][Train](40000/100000) average regularization: 0.07564717820361257\n",
      "[proc 0][Train](40000/100000) average loss: 0.4796506232813001\n",
      "[proc 1][Train] 20000 steps take 388.670 seconds\n",
      "[proc 1]sample: 67.139, forward: 166.633, backward: 68.320, update: 85.313\n",
      "[proc 0][Train](40000/100000) average regularization: 0.07569545411765576\n",
      "[proc 0][Train] 20000 steps take 388.671 seconds\n",
      "[proc 0]sample: 65.537, forward: 162.549, backward: 66.592, update: 85.345\n",
      "[0]Valid average MRR: 0.1884616495678395\n",
      "[0]Valid average MR: 223.69081276897097\n",
      "[0]Valid average HITS@1: 0.11725091245846271\n",
      "[0]Valid average HITS@3: 0.20673312632783133\n",
      "[0]Valid average HITS@10: 0.3168069401318298\n",
      "[proc 0]validation take 341.870 seconds:\n",
      "[1]Valid average MRR: 0.19008400381464352\n",
      "[1]Valid average MR: 222.0833191471976\n",
      "[1]Valid average HITS@1: 0.1186766718644668\n",
      "[1]Valid average HITS@3: 0.2084102221889321\n",
      "[1]Valid average HITS@10: 0.3189224892242113\n",
      "[proc 1]validation take 352.887 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.4021329833909869\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.40186119518727065\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.5419587707862258\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.5419527038156986\n",
      "[proc 0][Train](60000/100000) average loss: 0.4720458771660924\n",
      "[proc 1][Train](60000/100000) average loss: 0.471906949467957\n",
      "[proc 0][Train](60000/100000) average regularization: 0.07788852381370961\n",
      "[proc 0][Train] 20000 steps take 737.605 seconds\n",
      "[proc 0]sample: 64.824, forward: 159.871, backward: 67.369, update: 88.224\n",
      "[proc 1][Train](60000/100000) average regularization: 0.07784083704575896\n",
      "[proc 1][Train] 20000 steps take 737.611 seconds\n",
      "[proc 1]sample: 65.405, forward: 164.945, backward: 68.244, update: 80.456\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.39714159608334304\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3974163979634643\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.5390884955018759\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.5390534312561155\n",
      "[proc 0][Train](80000/100000) average loss: 0.4682349146038294\n",
      "[proc 1][Train](80000/100000) average loss: 0.46811504573374985\n",
      "[proc 0][Train](80000/100000) average regularization: 0.0795335237558931\n",
      "[proc 1][Train](80000/100000) average regularization: 0.07949019948914647\n",
      "[proc 0][Train] 20000 steps take 381.291 seconds\n",
      "[proc 0]sample: 66.029, forward: 161.923, backward: 68.070, update: 83.946\n",
      "[proc 1][Train] 20000 steps take 381.291 seconds\n",
      "[proc 1]sample: 64.847, forward: 165.297, backward: 67.513, update: 79.160\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.39183633596301076\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3921015601247549\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.5342252753064036\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.5340098807290197\n",
      "[proc 1][Train](100000/100000) average loss: 0.46303080563247206\n",
      "[proc 1][Train](100000/100000) average regularization: 0.08039886887557804\n",
      "[proc 0][Train](100000/100000) average loss: 0.46305572038441895\n",
      "[proc 1][Train] 20000 steps take 388.571 seconds\n",
      "[proc 1]sample: 66.745, forward: 165.821, backward: 69.743, update: 84.842\n",
      "[proc 0][Train](100000/100000) average regularization: 0.0804381685514003\n",
      "[proc 0][Train] 20000 steps take 388.577 seconds\n",
      "[proc 0]sample: 65.319, forward: 160.531, backward: 66.878, update: 85.482\n",
      "[0]Valid average MRR: 0.22731269206151322\n",
      "[0]Valid average MR: 190.36415944871166\n",
      "[0]Valid average HITS@1: 0.14723266328920848\n",
      "[0]Valid average HITS@3: 0.25056858419131667\n",
      "[0]Valid average HITS@10: 0.3760077899438906\n",
      "[proc 0]validation take 331.339 seconds:\n",
      "[1]Valid average MRR: 0.22779628337957006\n",
      "[1]Valid average MR: 188.3008811292618\n",
      "[1]Valid average HITS@1: 0.14782747843139926\n",
      "[1]Valid average HITS@3: 0.2502196013809352\n",
      "[1]Valid average HITS@10: 0.3766112612950013\n",
      "[proc 1]validation take 333.800 seconds:\n",
      "proc 1 takes 2624.604 seconds\n",
      "proc 0 takes 2624.608 seconds\n",
      "training takes 2625.0830454826355 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_3\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.22787261718790583\n",
      "Test average MR : 191.48701628114424\n",
      "Test average HITS@1 : 0.14793813029001002\n",
      "Test average HITS@3 : 0.25094479663890723\n",
      "Test average HITS@10 : 0.37567838101009826\n",
      "-----------------------------------------\n",
      "testing takes 341.586 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 12.0 --lr 0.01 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: 6, **12**, 18\n",
    "\n",
    "- lr: 0.01, **0.05**, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.322 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.370027288495518\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.37043411249455765\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5143995080024004\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5151743978723884\n",
      "[proc 0][Train](20000/100000) average loss: 0.44280425541996954\n",
      "[proc 1][Train](20000/100000) average loss: 0.44221339819282296\n",
      "[proc 0][Train](20000/100000) average regularization: 0.0806785118003082\n",
      "[proc 1][Train](20000/100000) average regularization: 0.08070548774915615\n",
      "[proc 0][Train] 20000 steps take 385.752 seconds\n",
      "[proc 0]sample: 65.819, forward: 161.714, backward: 63.654, update: 80.709\n",
      "[proc 1][Train] 20000 steps take 385.734 seconds\n",
      "[proc 1]sample: 67.872, forward: 161.818, backward: 68.955, update: 86.820\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.32998722126036883\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.32993491628170013\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.48068558107316495\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.480615615555644\n",
      "[proc 1][Train](40000/100000) average loss: 0.40533640112131836\n",
      "[proc 0][Train](40000/100000) average loss: 0.4052752659142017\n",
      "[proc 1][Train](40000/100000) average regularization: 0.08277819415219129\n",
      "[proc 0][Train](40000/100000) average regularization: 0.08277286381088197\n",
      "[proc 1][Train] 20000 steps take 379.410 seconds\n",
      "[proc 1]sample: 67.565, forward: 159.131, backward: 68.417, update: 83.905\n",
      "[proc 0][Train] 20000 steps take 379.414 seconds\n",
      "[proc 0]sample: 65.144, forward: 159.273, backward: 63.587, update: 79.114\n",
      "[0]Valid average MRR: 0.3935761590004903\n",
      "[0]Valid average MR: 83.21192528735632\n",
      "[0]Valid average HITS@1: 0.2785143269597429\n",
      "[0]Valid average HITS@3: 0.44852780955493815\n",
      "[0]Valid average HITS@10: 0.6150446696083238\n",
      "[proc 0]validation take 400.129 seconds:\n",
      "[1]Valid average MRR: 0.39419633359795353\n",
      "[1]Valid average MR: 82.58888578685388\n",
      "[1]Valid average HITS@1: 0.27972108922284944\n",
      "[1]Valid average HITS@3: 0.4486881796577623\n",
      "[1]Valid average HITS@10: 0.6150506955746066\n",
      "[proc 1]validation take 402.107 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.3186801438450813\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.318745443379879\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.4703449931070209\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.4702756961598992\n",
      "[proc 0][Train](60000/100000) average loss: 0.39451256857514383\n",
      "[proc 1][Train](60000/100000) average loss: 0.3945105698212981\n",
      "[proc 0][Train](60000/100000) average regularization: 0.08295771959200501\n",
      "[proc 1][Train](60000/100000) average regularization: 0.0829626369368285\n",
      "[proc 0][Train] 20000 steps take 778.048 seconds\n",
      "[proc 0]sample: 64.429, forward: 157.224, backward: 63.968, update: 81.125\n",
      "[proc 1][Train] 20000 steps take 778.050 seconds\n",
      "[proc 1]sample: 66.880, forward: 156.530, backward: 67.810, update: 81.715\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.31230129258483647\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.312371542583406\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.46408049633055926\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4638557610243559\n",
      "[proc 0][Train](80000/100000) average loss: 0.3881908944323659\n",
      "[proc 0][Train](80000/100000) average regularization: 0.0830439411483705\n",
      "[proc 1][Train](80000/100000) average loss: 0.38811365189850333\n",
      "[proc 0][Train] 20000 steps take 364.444 seconds\n",
      "[proc 0]sample: 63.985, forward: 156.283, backward: 63.444, update: 77.148\n",
      "[proc 1][Train](80000/100000) average regularization: 0.0830500944647938\n",
      "[proc 1][Train] 20000 steps take 364.451 seconds\n",
      "[proc 1]sample: 65.413, forward: 154.089, backward: 66.743, update: 77.942\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3080726884201169\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.3081441437676549\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.459629807330668\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.45946844733953474\n",
      "[proc 0][Train](100000/100000) average loss: 0.38385124784857033\n",
      "[proc 1][Train](100000/100000) average loss: 0.38380629559010265\n",
      "[proc 0][Train](100000/100000) average regularization: 0.08306601632051169\n",
      "[proc 1][Train](100000/100000) average regularization: 0.08307116091884673\n",
      "[proc 0][Train] 20000 steps take 364.461 seconds\n",
      "[proc 0]sample: 63.749, forward: 156.711, backward: 63.447, update: 77.632\n",
      "[proc 1][Train] 20000 steps take 364.453 seconds\n",
      "[proc 1]sample: 64.981, forward: 154.249, backward: 66.466, update: 78.272\n",
      "[1]Valid average MRR: 0.4069249131270877\n",
      "[1]Valid average MR: 73.55388234813458\n",
      "[1]Valid average HITS@1: 0.2813621414028613\n",
      "[1]Valid average HITS@3: 0.4720408288334911\n",
      "[1]Valid average HITS@10: 0.6497681417978033\n",
      "[proc 1]validation take 373.681 seconds:\n",
      "[0]Valid average MRR: 0.4059100089363876\n",
      "[0]Valid average MR: 73.85231791687094\n",
      "[0]Valid average HITS@1: 0.28049245519420385\n",
      "[0]Valid average HITS@3: 0.4706889742332625\n",
      "[0]Valid average HITS@10: 0.6490609849103884\n",
      "[proc 0]validation take 381.234 seconds:\n",
      "proc 0 takes 2653.352 seconds\n",
      "proc 1 takes 2653.332 seconds\n",
      "training takes 2653.844760656357 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_4\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.4058904323907377\n",
      "Test average MR : 74.7872556296261\n",
      "Test average HITS@1 : 0.28043266579053094\n",
      "Test average HITS@3 : 0.4709326079110972\n",
      "Test average HITS@10 : 0.6481168756000736\n",
      "-----------------------------------------\n",
      "testing takes 399.911 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 12.0 --lr 0.05 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: 6, **12**, 18\n",
    "\n",
    "- lr: 0.01, 0.05, **0.1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.288 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.33924800648953135\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.48900092038959264\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.33998573700760226\n",
      "[proc 1][Train](20000/100000) average loss: 0.41412446345835924\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.48968793203532696\n",
      "[proc 1][Train](20000/100000) average regularization: 0.08219836114375458\n",
      "[proc 1][Train] 20000 steps take 377.122 seconds\n",
      "[proc 1]sample: 65.979, forward: 160.265, backward: 66.515, update: 83.667\n",
      "[proc 0][Train](20000/100000) average loss: 0.414836834487319\n",
      "[proc 0][Train](20000/100000) average regularization: 0.0822182257020283\n",
      "[proc 0][Train] 20000 steps take 377.134 seconds\n",
      "[proc 0]sample: 65.255, forward: 161.314, backward: 62.694, update: 80.774\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.30492956209927796\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.304842635846138\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.4560634866461158\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.45590526515096425\n",
      "[proc 1][Train](40000/100000) average loss: 0.380496524310112\n",
      "[proc 0][Train](40000/100000) average loss: 0.3803739504367113\n",
      "[proc 1][Train](40000/100000) average regularization: 0.08317446173876523\n",
      "[proc 0][Train](40000/100000) average regularization: 0.08315881796628237\n",
      "[proc 1][Train] 20000 steps take 379.797 seconds\n",
      "[proc 1]sample: 67.302, forward: 160.244, backward: 67.542, update: 84.442\n",
      "[proc 0][Train] 20000 steps take 379.786 seconds\n",
      "[proc 0]sample: 64.720, forward: 157.225, backward: 61.895, update: 78.252\n",
      "[1]Valid average MRR: 0.4138044477228743\n",
      "[1]Valid average MR: 69.16591650380983\n",
      "[1]Valid average HITS@1: 0.28246185064382356\n",
      "[1]Valid average HITS@3: 0.4845802379185194\n",
      "[1]Valid average HITS@10: 0.6674792485206698\n",
      "[proc 1]validation take 374.605 seconds:\n",
      "[0]Valid average MRR: 0.41256351305900546\n",
      "[0]Valid average MR: 70.0702831344991\n",
      "[0]Valid average HITS@1: 0.28121084599880153\n",
      "[0]Valid average HITS@3: 0.4836846979353925\n",
      "[0]Valid average HITS@10: 0.6653933104537778\n",
      "[proc 0]validation take 382.193 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.298679940572381\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.29862034453451636\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.44902701053768396\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.4489647953882813\n",
      "[proc 1][Train](60000/100000) average loss: 0.3738534755676985\n",
      "[proc 0][Train](60000/100000) average loss: 0.373792570066452\n",
      "[proc 1][Train](60000/100000) average regularization: 0.08289352217800915\n",
      "[proc 0][Train](60000/100000) average regularization: 0.08287475511170923\n",
      "[proc 1][Train] 20000 steps take 752.477 seconds\n",
      "[proc 1]sample: 65.771, forward: 156.924, backward: 66.190, update: 81.140\n",
      "[proc 0][Train] 20000 steps take 752.478 seconds\n",
      "[proc 0]sample: 63.575, forward: 156.259, backward: 61.531, update: 76.935\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.2958145740121603\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.29575066176354886\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.44554627824425697\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4456687829107046\n",
      "[proc 1][Train](80000/100000) average loss: 0.3706804261237383\n",
      "[proc 0][Train](80000/100000) average loss: 0.37070972224026916\n",
      "[proc 1][Train](80000/100000) average regularization: 0.08261908753365278\n",
      "[proc 0][Train](80000/100000) average regularization: 0.08260632679052651\n",
      "[proc 1][Train] 20000 steps take 374.035 seconds\n",
      "[proc 1]sample: 65.922, forward: 157.432, backward: 65.855, update: 83.275\n",
      "[proc 0][Train] 20000 steps take 374.034 seconds\n",
      "[proc 0]sample: 65.385, forward: 157.687, backward: 62.793, update: 79.738\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.2940721654191613\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.29416082295030355\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.44352359186857937\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4435879637122154\n",
      "[proc 0][Train](100000/100000) average loss: 0.36879787878096104\n",
      "[proc 0][Train](100000/100000) average regularization: 0.08238971484079957\n",
      "[proc 1][Train](100000/100000) average loss: 0.3688743932455778\n",
      "[proc 0][Train] 20000 steps take 394.950 seconds\n",
      "[proc 0]sample: 64.036, forward: 155.582, backward: 61.632, update: 77.723\n",
      "[proc 1][Train](100000/100000) average regularization: 0.08240610234476627\n",
      "[proc 1][Train] 20000 steps take 394.954 seconds\n",
      "[proc 1]sample: 66.185, forward: 156.896, backward: 68.682, update: 102.916\n",
      "[1]Valid average MRR: 0.419027714882311\n",
      "[1]Valid average MR: 66.23961064164459\n",
      "[1]Valid average HITS@1: 0.28483831209952537\n",
      "[1]Valid average HITS@3: 0.4930408492615265\n",
      "[1]Valid average HITS@10: 0.6776490054951415\n",
      "[proc 1]validation take 365.766 seconds:\n",
      "[0]Valid average MRR: 0.41837934375893626\n",
      "[0]Valid average MR: 67.14377008770497\n",
      "[0]Valid average HITS@1: 0.2844521163588822\n",
      "[0]Valid average HITS@3: 0.49201939314702836\n",
      "[0]Valid average HITS@10: 0.6771258920302882\n",
      "[proc 0]validation take 383.031 seconds:\n",
      "proc 0 takes 2661.413 seconds\n",
      "proc 1 takes 2661.413 seconds\n",
      "training takes 2661.8827199935913 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_5\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.4177195586877162\n",
      "Test average MR : 67.57076101241344\n",
      "Test average HITS@1 : 0.28384074303574225\n",
      "Test average HITS@3 : 0.49194965170199584\n",
      "Test average HITS@10 : 0.6751704038622606\n",
      "-----------------------------------------\n",
      "testing takes 375.635 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 12.0 --lr 0.1 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: 6, 12, **18**\n",
    "\n",
    "- lr: **0.01**, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.311 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.4998116150424465\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.4995958993986711\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.6536074935168028\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.6556837328910827\n",
      "[proc 1][Train](20000/100000) average loss: 0.5767095541268588\n",
      "[proc 0][Train](20000/100000) average loss: 0.5776398161381483\n",
      "[proc 1][Train](20000/100000) average regularization: 0.19646815085912675\n",
      "[proc 0][Train](20000/100000) average regularization: 0.19642901883134217\n",
      "[proc 1][Train] 20000 steps take 393.839 seconds\n",
      "[proc 1]sample: 68.243, forward: 169.517, backward: 66.180, update: 87.948\n",
      "[proc 0][Train] 20000 steps take 393.843 seconds\n",
      "[proc 0]sample: 66.112, forward: 166.576, backward: 67.989, update: 90.415\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.4292644596263766\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.4294183384820819\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5913263951510191\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5913162676364183\n",
      "[proc 0][Train](40000/100000) average loss: 0.5102954273968935\n",
      "[proc 1][Train](40000/100000) average loss: 0.510367302800715\n",
      "[proc 0][Train](40000/100000) average regularization: 0.2019991270393133\n",
      "[proc 1][Train](40000/100000) average regularization: 0.2019911491945386\n",
      "[proc 0][Train] 20000 steps take 387.834 seconds\n",
      "[proc 0]sample: 67.200, forward: 164.321, backward: 68.512, update: 87.042\n",
      "[proc 1][Train] 20000 steps take 387.839 seconds\n",
      "[proc 1]sample: 66.882, forward: 162.667, backward: 64.259, update: 84.806\n",
      "[1]Valid average MRR: 0.13570997660700654\n",
      "[1]Valid average MR: 270.8261165623702\n",
      "[1]Valid average HITS@1: 0.07375882661364457\n",
      "[1]Valid average HITS@3: 0.14506628897498927\n",
      "[1]Valid average HITS@10: 0.24895646785648623\n",
      "[proc 1]validation take 366.397 seconds:\n",
      "[0]Valid average MRR: 0.13523827159352173\n",
      "[0]Valid average MR: 274.096083918941\n",
      "[0]Valid average HITS@1: 0.07369804434275753\n",
      "[0]Valid average HITS@3: 0.14473361660402026\n",
      "[0]Valid average HITS@10: 0.24759628479599063\n",
      "[proc 0]validation take 375.466 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.40356979311853647\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.4037086471602321\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.5752889068245888\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.5754556237339974\n",
      "[proc 1][Train](60000/100000) average loss: 0.489498776909709\n",
      "[proc 0][Train](60000/100000) average loss: 0.4895127085417509\n",
      "[proc 1][Train](60000/100000) average regularization: 0.20198674886375664\n",
      "[proc 0][Train](60000/100000) average regularization: 0.20199654736444353\n",
      "[proc 1][Train] 20000 steps take 762.578 seconds\n",
      "[proc 1]sample: 65.631, forward: 162.350, backward: 63.666, update: 84.701\n",
      "[proc 0][Train] 20000 steps take 762.582 seconds\n",
      "[proc 0]sample: 66.362, forward: 164.865, backward: 68.737, update: 86.858\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3913979035645723\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.5679886006057262\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.39154756586551664\n",
      "[proc 0][Train](80000/100000) average loss: 0.47969325211942193\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.5678864009261131\n",
      "[proc 0][Train](80000/100000) average regularization: 0.2023206919670105\n",
      "[proc 1][Train](80000/100000) average loss: 0.4797169833213091\n",
      "[proc 0][Train] 20000 steps take 401.781 seconds\n",
      "[proc 0]sample: 65.713, forward: 165.022, backward: 68.984, update: 101.770\n",
      "[proc 1][Train](80000/100000) average regularization: 0.20230916197970508\n",
      "[proc 1][Train] 20000 steps take 401.786 seconds\n",
      "[proc 1]sample: 65.554, forward: 161.537, backward: 63.845, update: 85.552\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.38472511203587056\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.3848561232507229\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.5652712492853403\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.5653564930737018\n",
      "[proc 0][Train](100000/100000) average loss: 0.4750408026084304\n",
      "[proc 1][Train](100000/100000) average loss: 0.4750636862561107\n",
      "[proc 0][Train](100000/100000) average regularization: 0.20308751849010587\n",
      "[proc 1][Train](100000/100000) average regularization: 0.20307807553187013\n",
      "[proc 0][Train] 20000 steps take 387.893 seconds\n",
      "[proc 0]sample: 65.639, forward: 165.571, backward: 68.342, update: 88.042\n",
      "[proc 1][Train] 20000 steps take 387.890 seconds\n",
      "[proc 1]sample: 65.140, forward: 161.026, backward: 63.862, update: 85.051\n",
      "[0]Valid average MRR: 0.1802571911784871\n",
      "[0]Valid average MR: 238.4513571117285\n",
      "[0]Valid average HITS@1: 0.11158890341559079\n",
      "[0]Valid average HITS@3: 0.1957768153837773\n",
      "[0]Valid average HITS@10: 0.3044342757531187\n",
      "[proc 0]validation take 359.902 seconds:\n",
      "[1]Valid average MRR: 0.1817561502550769\n",
      "[1]Valid average MR: 236.07416738732235\n",
      "[1]Valid average HITS@1: 0.11302491539388657\n",
      "[1]Valid average HITS@3: 0.19735184567300162\n",
      "[1]Valid average HITS@10: 0.3056885269343647\n",
      "[proc 1]validation take 369.272 seconds:\n",
      "proc 1 takes 2703.205 seconds\n",
      "proc 0 takes 2703.207 seconds\n",
      "training takes 2703.7385880947113 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_6\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.1803335510398743\n",
      "Test average MR : 238.92733577561845\n",
      "Test average HITS@1 : 0.11168347440026692\n",
      "Test average HITS@3 : 0.19589464581191227\n",
      "Test average HITS@10 : 0.30467733918029105\n",
      "-----------------------------------------\n",
      "testing takes 392.428 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 18.0 --lr 0.01 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: 6, 12, **18**\n",
    "\n",
    "- lr: 0.01, **0.05**, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.344 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.3695326031895\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.3700177718163956\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5534278594583273\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5542810828477144\n",
      "[proc 1][Train](20000/100000) average loss: 0.46148023129850624\n",
      "[proc 0][Train](20000/100000) average loss: 0.46214942715168\n",
      "[proc 1][Train](20000/100000) average regularization: 0.20227403198461252\n",
      "[proc 1][Train] 20000 steps take 383.889 seconds\n",
      "[proc 1]sample: 65.693, forward: 162.017, backward: 68.130, update: 87.771\n",
      "[proc 0][Train](20000/100000) average regularization: 0.20227912150801022\n",
      "[proc 0][Train] 20000 steps take 383.914 seconds\n",
      "[proc 0]sample: 64.411, forward: 158.539, backward: 64.023, update: 85.370\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3213267522275448\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.3212718461513519\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5104857992619276\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5105620835036039\n",
      "[proc 0][Train](40000/100000) average loss: 0.4159062758296728\n",
      "[proc 1][Train](40000/100000) average loss: 0.4159169647589326\n",
      "[proc 0][Train](40000/100000) average regularization: 0.1983534488134086\n",
      "[proc 1][Train](40000/100000) average regularization: 0.1983220579981804\n",
      "[proc 0][Train] 20000 steps take 386.045 seconds\n",
      "[proc 0]sample: 64.170, forward: 155.957, backward: 63.223, update: 81.115\n",
      "[proc 1][Train] 20000 steps take 386.049 seconds\n",
      "[proc 1]sample: 66.977, forward: 161.616, backward: 69.293, update: 87.876\n",
      "[1]Valid average MRR: 0.35231245554276325\n",
      "[1]Valid average MR: 106.45909285903974\n",
      "[1]Valid average HITS@1: 0.24849002771403475\n",
      "[1]Valid average HITS@3: 0.3933894877329647\n",
      "[1]Valid average HITS@10: 0.5555642563854634\n",
      "[proc 1]validation take 345.357 seconds:\n",
      "[0]Valid average MRR: 0.3517082416619387\n",
      "[0]Valid average MR: 108.2115916271722\n",
      "[0]Valid average HITS@1: 0.2479197308928474\n",
      "[0]Valid average HITS@3: 0.3933138584736068\n",
      "[0]Valid average HITS@10: 0.5548224110693468\n",
      "[proc 0]validation take 349.001 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.30726799171715974\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.30732514181286097\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.49818163194209336\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.498174380376935\n",
      "[proc 1][Train](60000/100000) average loss: 0.4027248117461801\n",
      "[proc 0][Train](60000/100000) average loss: 0.4027497609496117\n",
      "[proc 1][Train](60000/100000) average regularization: 0.19565807690322398\n",
      "[proc 0][Train](60000/100000) average regularization: 0.1956847384892404\n",
      "[proc 1][Train] 20000 steps take 728.078 seconds\n",
      "[proc 1]sample: 65.683, forward: 159.313, backward: 68.986, update: 84.739\n",
      "[proc 0][Train] 20000 steps take 728.081 seconds\n",
      "[proc 0]sample: 63.129, forward: 155.869, backward: 62.948, update: 79.011\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.29936028777062895\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.29942343759834766\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.49072658619880677\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.49084444660544396\n",
      "[proc 1][Train](80000/100000) average loss: 0.39504343693852423\n",
      "[proc 0][Train](80000/100000) average loss: 0.3951339422166347\n",
      "[proc 1][Train](80000/100000) average regularization: 0.19395652778297662\n",
      "[proc 0][Train](80000/100000) average regularization: 0.19397305060625075\n",
      "[proc 1][Train] 20000 steps take 376.053 seconds\n",
      "[proc 1]sample: 65.720, forward: 159.005, backward: 68.377, update: 82.189\n",
      "[proc 0][Train] 20000 steps take 376.052 seconds\n",
      "[proc 0]sample: 63.571, forward: 155.993, backward: 63.240, update: 77.978\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.2941007476449013\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.29405331839770077\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.4856516056627035\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.48570454769581556\n",
      "[proc 0][Train](100000/100000) average loss: 0.38987617666572333\n",
      "[proc 0][Train](100000/100000) average regularization: 0.1927802332751453\n",
      "[proc 1][Train](100000/100000) average loss: 0.38987893304377796\n",
      "[proc 0][Train] 20000 steps take 374.841 seconds\n",
      "[proc 0]sample: 63.098, forward: 156.609, backward: 63.529, update: 77.606\n",
      "[proc 1][Train](100000/100000) average regularization: 0.19276050359234215\n",
      "[proc 1][Train] 20000 steps take 374.847 seconds\n",
      "[proc 1]sample: 65.853, forward: 158.505, backward: 68.160, update: 82.042\n",
      "[1]Valid average MRR: 0.35821379801699993\n",
      "[1]Valid average MR: 92.08655699081419\n",
      "[1]Valid average HITS@1: 0.24082610975302504\n",
      "[1]Valid average HITS@3: 0.40711031820069865\n",
      "[1]Valid average HITS@10: 0.5956304432202755\n",
      "[proc 1]validation take 314.999 seconds:\n",
      "[0]Valid average MRR: 0.35728452583197523\n",
      "[0]Valid average MR: 94.07067467451108\n",
      "[0]Valid average HITS@1: 0.23968377185814677\n",
      "[0]Valid average HITS@3: 0.4067555973198235\n",
      "[0]Valid average HITS@10: 0.5945484011548728\n",
      "[proc 0]validation take 334.649 seconds:\n",
      "proc 0 takes 2583.583 seconds\n",
      "proc 1 takes 2583.561 seconds\n",
      "training takes 2584.0636410713196 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_7\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.35707082430729176\n",
      "Test average MR : 94.28942610839115\n",
      "Test average HITS@1 : 0.23938252858222625\n",
      "Test average HITS@3 : 0.4068856098109045\n",
      "Test average HITS@10 : 0.5943843330586898\n",
      "-----------------------------------------\n",
      "testing takes 359.319 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 18.0 --lr 0.05 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: **200**, 400\n",
    "\n",
    "- gamma: 6, 12, **18**\n",
    "\n",
    "- lr: 0.01, 0.05, **0.1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.236 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.33366552463637345\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.33336762295381034\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5239051952943206\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5234487918436527\n",
      "[proc 0][Train](20000/100000) average loss: 0.42878535999059675\n",
      "[proc 1][Train](20000/100000) average loss: 0.42840820744931696\n",
      "[proc 0][Train](20000/100000) average regularization: 0.1974521633577526\n",
      "[proc 1][Train](20000/100000) average regularization: 0.19745695398342358\n",
      "[proc 0][Train] 20000 steps take 386.219 seconds\n",
      "[proc 0]sample: 66.743, forward: 164.948, backward: 65.803, update: 87.995\n",
      "[proc 1][Train] 20000 steps take 386.209 seconds\n",
      "[proc 1]sample: 65.577, forward: 160.042, backward: 65.017, update: 88.489\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.29070954403728244\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.48214965295642614\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.29079195024371146\n",
      "[proc 1][Train](40000/100000) average loss: 0.3864295985490084\n",
      "[proc 1][Train](40000/100000) average regularization: 0.1915454523034394\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.4822008893623948\n",
      "[proc 1][Train] 20000 steps take 375.385 seconds\n",
      "[proc 1]sample: 64.546, forward: 153.926, backward: 64.125, update: 86.082\n",
      "[proc 0][Train](40000/100000) average loss: 0.3864964197739959\n",
      "[proc 0][Train](40000/100000) average regularization: 0.19153762488290668\n",
      "[proc 0][Train] 20000 steps take 375.396 seconds\n",
      "[proc 0]sample: 66.181, forward: 159.019, backward: 64.768, update: 84.952\n",
      "[1]Valid average MRR: 0.360460030016181\n",
      "[1]Valid average MR: 85.33448865222631\n",
      "[1]Valid average HITS@1: 0.2347589832285829\n",
      "[1]Valid average HITS@3: 0.4146108118782217\n",
      "[1]Valid average HITS@10: 0.6189320223074147\n",
      "[proc 1]validation take 398.887 seconds:\n",
      "[0]Valid average MRR: 0.3598011334098305\n",
      "[0]Valid average MR: 87.61558601623359\n",
      "[0]Valid average HITS@1: 0.23367448384812334\n",
      "[0]Valid average HITS@3: 0.41414378711118377\n",
      "[0]Valid average HITS@10: 0.6190417824263224\n",
      "[proc 0]validation take 412.212 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.2817798694849014\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.2818304296836257\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.4727322855517268\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.47271941222250463\n",
      "[proc 1][Train](60000/100000) average loss: 0.3772560776233673\n",
      "[proc 0][Train](60000/100000) average loss: 0.37727492087334397\n",
      "[proc 1][Train](60000/100000) average regularization: 0.1891590621225536\n",
      "[proc 1][Train] 20000 steps take 796.355 seconds\n",
      "[proc 1]sample: 65.351, forward: 159.325, backward: 66.085, update: 86.377\n",
      "[proc 0][Train](60000/100000) average regularization: 0.18914957470148802\n",
      "[proc 0][Train] 20000 steps take 796.352 seconds\n",
      "[proc 0]sample: 65.039, forward: 164.937, backward: 67.641, update: 85.769\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.2776120363369584\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.2776459636211395\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.46795361763089893\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4678951432049274\n",
      "[proc 0][Train](80000/100000) average loss: 0.3727997906625271\n",
      "[proc 0][Train](80000/100000) average regularization: 0.18786180571243166\n",
      "[proc 1][Train](80000/100000) average loss: 0.37275358974933626\n",
      "[proc 0][Train] 20000 steps take 380.595 seconds\n",
      "[proc 0]sample: 63.871, forward: 163.893, backward: 67.915, update: 84.272\n",
      "[proc 1][Train](80000/100000) average regularization: 0.18786970810443163\n",
      "[proc 1][Train] 20000 steps take 380.610 seconds\n",
      "[proc 1]sample: 64.933, forward: 156.196, backward: 65.793, update: 85.456\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.2752902441397309\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.27524624151587485\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.46508707236647606\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4650348323494196\n",
      "[proc 0][Train](100000/100000) average loss: 0.3701886582642794\n",
      "[proc 0][Train](100000/100000) average regularization: 0.18705781709477307\n",
      "[proc 1][Train](100000/100000) average loss: 0.37014053689092397\n",
      "[proc 0][Train] 20000 steps take 394.228 seconds\n",
      "[proc 0]sample: 63.879, forward: 165.239, backward: 68.964, update: 94.972\n",
      "[proc 1][Train](100000/100000) average regularization: 0.1870592437326908\n",
      "[proc 1][Train] 20000 steps take 394.223 seconds\n",
      "[proc 1]sample: 66.041, forward: 161.651, backward: 66.707, update: 86.306\n",
      "[0]Valid average MRR: 0.36241274851052147\n",
      "[0]Valid average MR: 84.07679972217683\n",
      "[0]Valid average HITS@1: 0.23175083074576455\n",
      "[0]Valid average HITS@3: 0.4196423707577491\n",
      "[0]Valid average HITS@10: 0.6322383831780792\n",
      "[proc 0]validation take 397.656 seconds:\n",
      "[1]Valid average MRR: 0.3629433550328978\n",
      "[1]Valid average MR: 82.15939315116066\n",
      "[1]Valid average HITS@1: 0.23302600488910982\n",
      "[1]Valid average HITS@3: 0.41922073854157443\n",
      "[1]Valid average HITS@10: 0.6330069387227031\n",
      "[proc 1]validation take 401.701 seconds:\n",
      "proc 1 takes 2734.483 seconds\n",
      "proc 0 takes 2734.495 seconds\n",
      "training takes 2734.999101161957 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_8\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.36229195909956796\n",
      "Test average MR : 84.65601912064116\n",
      "Test average HITS@1 : 0.2325936114723847\n",
      "Test average HITS@3 : 0.41878153577970406\n",
      "Test average HITS@10 : 0.6309964795685599\n",
      "-----------------------------------------\n",
      "testing takes 394.650 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 200 \\\n",
    "--gamma 18.0 --lr 0.1 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 10\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: **6**, 12, 18\n",
    "\n",
    "- lr: **0.01**, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.470 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.4252923823406454\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.42562615928410086\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5355704292580485\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5357596437484026\n",
      "[proc 0][Train](20000/100000) average loss: 0.48043140585124494\n",
      "[proc 1][Train](20000/100000) average loss: 0.48069290158599615\n",
      "[proc 1][Train](20000/100000) average regularization: 0.015304234612732188\n",
      "[proc 0][Train](20000/100000) average regularization: 0.015341624993606563\n",
      "[proc 1][Train] 20000 steps take 587.576 seconds\n",
      "[proc 1]sample: 72.010, forward: 250.824, backward: 71.226, update: 124.568\n",
      "[proc 0][Train] 20000 steps take 587.576 seconds\n",
      "[proc 0]sample: 71.788, forward: 250.423, backward: 72.375, update: 192.655\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3973446582570672\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.3969346317395568\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5088478257805109\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5088903769671917\n",
      "[proc 0][Train](40000/100000) average loss: 0.4530962419256568\n",
      "[proc 1][Train](40000/100000) average loss: 0.4529125044390559\n",
      "[proc 0][Train](40000/100000) average regularization: 0.018872952707204967\n",
      "[proc 1][Train](40000/100000) average regularization: 0.018871863338537513\n",
      "[proc 0][Train] 20000 steps take 535.270 seconds\n",
      "[proc 0]sample: 70.108, forward: 257.117, backward: 69.544, update: 137.304\n",
      "[proc 1][Train] 20000 steps take 535.271 seconds\n",
      "[proc 1]sample: 70.919, forward: 256.107, backward: 72.045, update: 124.716\n",
      "[0]Valid average MRR: 0.33288443038656285\n",
      "[0]Valid average MR: 128.08090238056326\n",
      "[0]Valid average HITS@1: 0.2402898077027837\n",
      "[0]Valid average HITS@3: 0.3673973143759874\n",
      "[0]Valid average HITS@10: 0.5095093152475895\n",
      "[proc 0]validation take 403.643 seconds:\n",
      "[1]Valid average MRR: 0.33362482911057173\n",
      "[1]Valid average MR: 125.76603430548084\n",
      "[1]Valid average HITS@1: 0.2407784443370081\n",
      "[1]Valid average HITS@3: 0.3682527901291733\n",
      "[1]Valid average HITS@10: 0.5107791933649741\n",
      "[proc 1]validation take 425.167 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.3895269682586193\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.3899368514493108\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.4979960296705365\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.49788568388670684\n",
      "[proc 1][Train](60000/100000) average loss: 0.44376149897277356\n",
      "[proc 1][Train](60000/100000) average regularization: 0.019835988056845964\n",
      "[proc 0][Train](60000/100000) average loss: 0.4439112675637007\n",
      "[proc 1][Train] 20000 steps take 932.195 seconds\n",
      "[proc 1]sample: 68.539, forward: 248.855, backward: 69.760, update: 116.112\n",
      "[proc 0][Train](60000/100000) average regularization: 0.019837048109527678\n",
      "[proc 0][Train] 20000 steps take 932.201 seconds\n",
      "[proc 0]sample: 69.379, forward: 241.789, backward: 68.173, update: 120.904\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.38581924069672824\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3861974243119359\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.49020463163256645\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4902126346707344\n",
      "[proc 1][Train](80000/100000) average loss: 0.4380119361698627\n",
      "[proc 0][Train](80000/100000) average loss: 0.4382050296410918\n",
      "[proc 1][Train](80000/100000) average regularization: 0.020315228373836727\n",
      "[proc 0][Train](80000/100000) average regularization: 0.020315861757379025\n",
      "[proc 1][Train] 20000 steps take 499.660 seconds\n",
      "[proc 1]sample: 67.857, forward: 248.201, backward: 68.711, update: 109.944\n",
      "[proc 0][Train] 20000 steps take 499.659 seconds\n",
      "[proc 0]sample: 69.171, forward: 236.022, backward: 67.467, update: 118.609\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3839009333714843\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.48380299493670464\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.383559584826231\n",
      "[proc 0][Train](100000/100000) average loss: 0.43385196413695815\n",
      "[proc 0][Train](100000/100000) average regularization: 0.020576949893776328\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.483768959826231\n",
      "[proc 0][Train] 20000 steps take 507.689 seconds\n",
      "[proc 0]sample: 68.613, forward: 227.318, backward: 65.581, update: 122.205\n",
      "[proc 1][Train](100000/100000) average loss: 0.4336642722025514\n",
      "[proc 1][Train](100000/100000) average regularization: 0.020576597310509533\n",
      "[proc 1][Train] 20000 steps take 507.701 seconds\n",
      "[proc 1]sample: 70.148, forward: 248.337, backward: 69.811, update: 118.855\n",
      "[0]Valid average MRR: 0.37350078020018523\n",
      "[0]Valid average MR: 101.97766860053386\n",
      "[0]Valid average HITS@1: 0.2744320967478346\n",
      "[0]Valid average HITS@3: 0.41502560331208804\n",
      "[0]Valid average HITS@10: 0.5635997167293131\n",
      "[proc 0]validation take 381.342 seconds:\n",
      "[1]Valid average MRR: 0.3743371509976858\n",
      "[1]Valid average MR: 100.53971891023241\n",
      "[1]Valid average HITS@1: 0.2751758513383768\n",
      "[1]Valid average HITS@3: 0.41563902299515854\n",
      "[1]Valid average HITS@10: 0.5644742845080588\n",
      "[proc 1]validation take 401.346 seconds:\n",
      "proc 1 takes 3463.750 seconds\n",
      "proc 0 takes 3463.750 seconds\n",
      "training takes 3464.2642192840576 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_9\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.3731278752701238\n",
      "Test average MR : 101.96226771621373\n",
      "Test average HITS@1 : 0.2744353350538279\n",
      "Test average HITS@3 : 0.41435716377156007\n",
      "Test average HITS@10 : 0.5619599338131652\n",
      "-----------------------------------------\n",
      "testing takes 404.608 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 6.0 --lr 0.01 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: **6**, 12, 18\n",
    "\n",
    "- lr: 0.01, **0.05**, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.470 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.37769943681762086\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.3777260833585402\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.46366627268493177\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.4635497196130455\n",
      "[proc 1][Train](20000/100000) average loss: 0.4206828547641635\n",
      "[proc 1][Train](20000/100000) average regularization: 0.019645876182660043\n",
      "[proc 0][Train](20000/100000) average loss: 0.4206379014641047\n",
      "[proc 1][Train] 20000 steps take 571.263 seconds\n",
      "[proc 1]sample: 68.031, forward: 238.936, backward: 70.597, update: 111.151\n",
      "[proc 0][Train](20000/100000) average regularization: 0.019664745633229057\n",
      "[proc 0][Train] 20000 steps take 571.271 seconds\n",
      "[proc 0]sample: 71.580, forward: 236.134, backward: 76.306, update: 186.913\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.36551831071823837\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3654883867457509\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.44264644085466864\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.4427105970859528\n",
      "[proc 1][Train](40000/100000) average loss: 0.40408237587213514\n",
      "[proc 0][Train](40000/100000) average loss: 0.40409949196428063\n",
      "[proc 1][Train](40000/100000) average regularization: 0.020127960111573338\n",
      "[proc 0][Train](40000/100000) average regularization: 0.020125324165914206\n",
      "[proc 1][Train] 20000 steps take 562.266 seconds\n",
      "[proc 0][Train] 20000 steps take 562.258 seconds\n",
      "[proc 1]sample: 67.530, forward: 234.668, backward: 69.985, update: 108.161\n",
      "[proc 0]sample: 70.821, forward: 228.747, backward: 76.017, update: 186.335\n",
      "[1]Valid average MRR: 0.43280523184379754\n",
      "[1]Valid average MR: 71.35401785410298\n",
      "[1]Valid average HITS@1: 0.3141695663128077\n",
      "[1]Valid average HITS@3: 0.4978107955357933\n",
      "[1]Valid average HITS@10: 0.6551100730642734\n",
      "[proc 1]validation take 378.404 seconds:\n",
      "[0]Valid average MRR: 0.4309084996890142\n",
      "[0]Valid average MR: 72.63799572370213\n",
      "[0]Valid average HITS@1: 0.31108024186958655\n",
      "[0]Valid average HITS@3: 0.49776651958380996\n",
      "[0]Valid average HITS@10: 0.6547093751702348\n",
      "[proc 0]validation take 387.364 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.36356754557341336\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.3636197914168239\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.43951616732031107\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.4394025473952293\n",
      "[proc 1][Train](60000/100000) average loss: 0.40156797931194305\n",
      "[proc 0][Train](60000/100000) average loss: 0.40148504647910593\n",
      "[proc 1][Train](60000/100000) average regularization: 0.01985963922319934\n",
      "[proc 0][Train](60000/100000) average regularization: 0.0198560926633887\n",
      "[proc 1][Train] 20000 steps take 941.026 seconds\n",
      "[proc 1]sample: 66.256, forward: 231.814, backward: 70.189, update: 105.153\n",
      "[proc 0][Train] 20000 steps take 941.029 seconds\n",
      "[proc 0]sample: 69.543, forward: 223.223, backward: 74.265, update: 186.299\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.36284425571262835\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3627791887223721\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4379878770828247\n",
      "[proc 1][Train](80000/100000) average loss: 0.40041606639325616\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4381363885343075\n",
      "[proc 1][Train](80000/100000) average regularization: 0.01966703956183046\n",
      "[proc 0][Train](80000/100000) average loss: 0.4004577885836363\n",
      "[proc 1][Train] 20000 steps take 544.648 seconds\n",
      "[proc 1]sample: 65.827, forward: 226.135, backward: 69.901, update: 102.210\n",
      "[proc 0][Train](80000/100000) average regularization: 0.019663931238185613\n",
      "[proc 0][Train] 20000 steps take 544.657 seconds\n",
      "[proc 0]sample: 68.639, forward: 215.582, backward: 72.783, update: 187.326\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3621786950826645\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.36226728687286375\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.43706667731553317\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.43716557883024215\n",
      "[proc 1][Train](100000/100000) average loss: 0.39966698210835455\n",
      "[proc 0][Train](100000/100000) average loss: 0.39967213699817655\n",
      "[proc 1][Train](100000/100000) average regularization: 0.019528540255036204\n",
      "[proc 0][Train](100000/100000) average regularization: 0.019525754607003183\n",
      "[proc 1][Train] 20000 steps take 550.170 seconds\n",
      "[proc 1]sample: 66.255, forward: 233.998, backward: 70.915, update: 103.679\n",
      "[proc 0][Train] 20000 steps take 550.160 seconds\n",
      "[proc 0]sample: 69.908, forward: 228.082, backward: 74.649, update: 177.189\n",
      "[1]Valid average MRR: 0.4360053122241365\n",
      "[1]Valid average MR: 69.44146686913119\n",
      "[1]Valid average HITS@1: 0.3160114941746052\n",
      "[1]Valid average HITS@3: 0.5026794773146667\n",
      "[1]Valid average HITS@10: 0.6598017118693695\n",
      "[proc 1]validation take 362.420 seconds:\n",
      "[0]Valid average MRR: 0.4348720794271351\n",
      "[0]Valid average MR: 70.76965871329737\n",
      "[0]Valid average HITS@1: 0.31477774146102305\n",
      "[0]Valid average HITS@3: 0.5019236531023588\n",
      "[0]Valid average HITS@10: 0.659292095658332\n",
      "[proc 0]validation take 373.319 seconds:\n",
      "proc 0 takes 3542.695 seconds\n",
      "proc 1 takes 3542.695 seconds\n",
      "training takes 3543.2138760089874 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_10\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.4344135479904278\n",
      "Test average MR : 70.8893157969998\n",
      "Test average HITS@1 : 0.3146121737472507\n",
      "Test average HITS@3 : 0.5011252442852571\n",
      "Test average HITS@10 : 0.6580227704501658\n",
      "-----------------------------------------\n",
      "testing takes 392.205 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 6.0 --lr 0.05 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 12\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: **6**, 12, 18\n",
    "\n",
    "- lr: 0.01, 0.05, **0.1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.353 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.3744199490193045\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.3737929284764221\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.4498363884894177\n",
      "[proc 0][Train](20000/100000) average loss: 0.4121281688928604\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.45016019742414354\n",
      "[proc 0][Train](20000/100000) average regularization: 0.019895828422545912\n",
      "[proc 1][Train](20000/100000) average loss: 0.41197656286507844\n",
      "[proc 0][Train] 20000 steps take 611.720 seconds\n",
      "[proc 0]sample: 70.977, forward: 232.744, backward: 72.769, update: 234.891\n",
      "[proc 1][Train](20000/100000) average regularization: 0.020020717396313115\n",
      "[proc 1][Train] 20000 steps take 611.727 seconds\n",
      "[proc 1]sample: 68.428, forward: 243.351, backward: 67.345, update: 107.899\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.36345155183374883\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.36323957501351833\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.43803001353889703\n",
      "[proc 0][Train](40000/100000) average loss: 0.40074078276455405\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.43833540006428956\n",
      "[proc 0][Train](40000/100000) average regularization: 0.01950169991692528\n",
      "[proc 0][Train] 20000 steps take 637.072 seconds\n",
      "[proc 0]sample: 71.056, forward: 228.270, backward: 72.639, update: 264.767\n",
      "[proc 1][Train](40000/100000) average loss: 0.40078748746067283\n",
      "[proc 1][Train](40000/100000) average regularization: 0.019500210285186767\n",
      "[proc 1][Train] 20000 steps take 637.074 seconds\n",
      "[proc 1]sample: 68.430, forward: 239.207, backward: 67.980, update: 105.538\n",
      "[1]Valid average MRR: 0.4339759464576333\n",
      "[1]Valid average MR: 69.79043559380894\n",
      "[1]Valid average HITS@1: 0.3136997214977836\n",
      "[1]Valid average HITS@3: 0.5005924130276391\n",
      "[1]Valid average HITS@10: 0.6597131903824809\n",
      "[proc 1]validation take 369.279 seconds:\n",
      "[0]Valid average MRR: 0.43221191816827276\n",
      "[0]Valid average MR: 71.09007122623522\n",
      "[0]Valid average HITS@1: 0.31132197526829003\n",
      "[0]Valid average HITS@3: 0.49889687857493054\n",
      "[0]Valid average HITS@10: 0.6594214740970746\n",
      "[proc 0]validation take 370.143 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.3625811923995614\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.3624316172614694\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.43662566372007133\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.43695623461306093\n",
      "[proc 0][Train](60000/100000) average loss: 0.39960342814028266\n",
      "[proc 1][Train](60000/100000) average loss: 0.39969392603486775\n",
      "[proc 0][Train](60000/100000) average regularization: 0.019237785765901207\n",
      "[proc 1][Train](60000/100000) average regularization: 0.019236051817703992\n",
      "[proc 0][Train] 20000 steps take 1013.280 seconds\n",
      "[proc 0]sample: 70.849, forward: 226.612, backward: 72.691, update: 272.640\n",
      "[proc 1][Train] 20000 steps take 1013.274 seconds\n",
      "[proc 1]sample: 68.523, forward: 238.961, backward: 68.311, update: 108.831\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.36218545352071524\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.36219877905845643\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4360139538809657\n",
      "[proc 0][Train](80000/100000) average loss: 0.3990997035995126\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4362940746471286\n",
      "[proc 0][Train](80000/100000) average regularization: 0.01909585800971836\n",
      "[proc 0][Train] 20000 steps take 557.718 seconds\n",
      "[proc 0]sample: 70.700, forward: 236.742, backward: 70.109, update: 175.145\n",
      "[proc 1][Train](80000/100000) average loss: 0.39924642684161665\n",
      "[proc 1][Train](80000/100000) average regularization: 0.019092862997576593\n",
      "[proc 1][Train] 20000 steps take 557.733 seconds\n",
      "[proc 1]sample: 70.029, forward: 244.232, backward: 68.785, update: 111.279\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.3620267526566982\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.4356888059437275\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.36189714274257423\n",
      "[proc 0][Train](100000/100000) average loss: 0.3988577793121338\n",
      "[proc 0][Train](100000/100000) average regularization: 0.01900439125066623\n",
      "[proc 0][Train] 20000 steps take 498.632 seconds\n",
      "[proc 0]sample: 68.684, forward: 241.521, backward: 66.689, update: 119.325\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4358622501537204\n",
      "[proc 1][Train](100000/100000) average loss: 0.3988796964645386\n",
      "[proc 1][Train](100000/100000) average regularization: 0.01900155825037509\n",
      "[proc 1][Train] 20000 steps take 498.633 seconds\n",
      "[proc 1]sample: 70.003, forward: 235.509, backward: 67.423, update: 120.385\n",
      "[0]Valid average MRR: 0.4340395155559925\n",
      "[0]Valid average MR: 70.13165277550799\n",
      "[0]Valid average HITS@1: 0.31262256904722996\n",
      "[0]Valid average HITS@3: 0.5022539085907284\n",
      "[0]Valid average HITS@10: 0.6604939532603367\n",
      "[proc 0]validation take 353.984 seconds:\n",
      "[1]Valid average MRR: 0.4352961100840235\n",
      "[1]Valid average MR: 68.86682963699381\n",
      "[1]Valid average HITS@1: 0.31420361303853406\n",
      "[1]Valid average HITS@3: 0.5024547689248725\n",
      "[1]Valid average HITS@10: 0.6614870247928257\n",
      "[proc 1]validation take 369.334 seconds:\n",
      "proc 1 takes 3687.776 seconds\n",
      "proc 0 takes 3687.776 seconds\n",
      "training takes 3688.2681562900543 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_11\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.43387255865724705\n",
      "Test average MR : 70.18763661248698\n",
      "Test average HITS@1 : 0.3127038547702867\n",
      "Test average HITS@3 : 0.5017193596491826\n",
      "Test average HITS@10 : 0.659532742736131\n",
      "-----------------------------------------\n",
      "testing takes 363.370 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 6.0 --lr 0.1 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 13\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: 6, **12**, 18\n",
    "\n",
    "- lr: **0.01**, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.378 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.4561141348781499\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.45624417525460287\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5646996444880963\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5635756308928132\n",
      "[proc 0][Train](20000/100000) average loss: 0.5104068897455931\n",
      "[proc 0][Train](20000/100000) average regularization: 0.05500451066512187\n",
      "[proc 1][Train](20000/100000) average loss: 0.5099099030315876\n",
      "[proc 0][Train] 20000 steps take 523.474 seconds\n",
      "[proc 0]sample: 70.338, forward: 253.778, backward: 69.797, update: 126.690\n",
      "[proc 1][Train](20000/100000) average regularization: 0.054987843256918544\n",
      "[proc 1][Train] 20000 steps take 523.473 seconds\n",
      "[proc 1]sample: 70.090, forward: 238.689, backward: 67.703, update: 135.667\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.4100841292515397\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5374532790064812\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.40995730039030315\n",
      "[proc 0][Train](40000/100000) average loss: 0.47376870414465666\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5374993806555867\n",
      "[proc 0][Train](40000/100000) average regularization: 0.059735889714211225\n",
      "[proc 0][Train] 20000 steps take 525.672 seconds\n",
      "[proc 1][Train](40000/100000) average loss: 0.4737283405408263\n",
      "[proc 0]sample: 69.763, forward: 253.654, backward: 68.867, update: 126.695\n",
      "[proc 1][Train](40000/100000) average regularization: 0.059712838747911154\n",
      "[proc 1][Train] 20000 steps take 525.670 seconds\n",
      "[proc 1]sample: 72.536, forward: 252.253, backward: 69.780, update: 128.572\n",
      "[1]Valid average MRR: 0.22586566408001205\n",
      "[1]Valid average MR: 190.7549793336375\n",
      "[1]Valid average HITS@1: 0.14556337117059454\n",
      "[1]Valid average HITS@3: 0.2491811762462804\n",
      "[1]Valid average HITS@10: 0.37480678483150276\n",
      "[proc 1]validation take 373.617 seconds:\n",
      "[0]Valid average MRR: 0.22499730718341387\n",
      "[0]Valid average MR: 192.7716947213597\n",
      "[0]Valid average HITS@1: 0.1451728223565942\n",
      "[0]Valid average HITS@3: 0.2474464781827096\n",
      "[0]Valid average HITS@10: 0.3736381216974451\n",
      "[proc 0]validation take 376.701 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.4015318465128541\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.40169536857008936\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.5302811007216572\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.530222169239819\n",
      "[proc 1][Train](60000/100000) average loss: 0.4659064735978842\n",
      "[proc 0][Train](60000/100000) average loss: 0.46595876876562836\n",
      "[proc 1][Train](60000/100000) average regularization: 0.061583434854634106\n",
      "[proc 1][Train] 20000 steps take 924.444 seconds\n",
      "[proc 1]sample: 68.647, forward: 230.551, backward: 66.697, update: 132.656\n",
      "[proc 0][Train](60000/100000) average regularization: 0.06160788838881999\n",
      "[proc 0][Train] 20000 steps take 924.456 seconds\n",
      "[proc 0]sample: 69.479, forward: 245.149, backward: 70.655, update: 161.566\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.3931967635497451\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.3930167800799012\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.522171174377203\n",
      "[proc 0][Train](80000/100000) average loss: 0.45768396902382374\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.5222457045152783\n",
      "[proc 0][Train](80000/100000) average regularization: 0.06235761973075569\n",
      "[proc 1][Train](80000/100000) average loss: 0.45763124223947527\n",
      "[proc 0][Train] 20000 steps take 538.230 seconds\n",
      "[proc 0]sample: 68.290, forward: 238.346, backward: 70.486, update: 159.406\n",
      "[proc 1][Train](80000/100000) average regularization: 0.06234005747549236\n",
      "[proc 1][Train] 20000 steps take 538.243 seconds\n",
      "[proc 1]sample: 68.784, forward: 229.924, backward: 66.596, update: 130.698\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.38648555542677643\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.3862496435433626\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.5163414041727782\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.5161709143579006\n",
      "[proc 0][Train](100000/100000) average loss: 0.45141347977221014\n",
      "[proc 1][Train](100000/100000) average loss: 0.4512102788597345\n",
      "[proc 0][Train](100000/100000) average regularization: 0.06279496698323637\n",
      "[proc 1][Train](100000/100000) average regularization: 0.06277802978493273\n",
      "[proc 0][Train] 20000 steps take 516.507 seconds\n",
      "[proc 0]sample: 70.792, forward: 251.531, backward: 70.600, update: 122.424\n",
      "[proc 1][Train] 20000 steps take 516.501 seconds\n",
      "[proc 1]sample: 67.762, forward: 226.657, backward: 66.133, update: 137.039\n",
      "[0]Valid average MRR: 0.2785167394881829\n",
      "[0]Valid average MR: 156.24436522852318\n",
      "[0]Valid average HITS@1: 0.19065274827041456\n",
      "[0]Valid average HITS@3: 0.3069128942637686\n",
      "[0]Valid average HITS@10: 0.4446328376096312\n",
      "[proc 0]validation take 356.278 seconds:\n",
      "[1]Valid average MRR: 0.27957138229044726\n",
      "[1]Valid average MR: 153.88232430187188\n",
      "[1]Valid average HITS@1: 0.19170349387499405\n",
      "[1]Valid average HITS@3: 0.30751343143329907\n",
      "[1]Valid average HITS@10: 0.4458180406790279\n",
      "[proc 1]validation take 358.299 seconds:\n",
      "proc 1 takes 3386.629 seconds\n",
      "proc 0 takes 3386.639 seconds\n",
      "training takes 3387.118340730667 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_12\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.2786946499157326\n",
      "Test average MR : 156.6186851835459\n",
      "Test average HITS@1 : 0.19138515698945233\n",
      "Test average HITS@3 : 0.3064426619092042\n",
      "Test average HITS@10 : 0.4440493132775421\n",
      "-----------------------------------------\n",
      "testing takes 359.705 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 12.0 --lr 0.01 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 14\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: 6, **12**, 18\n",
    "\n",
    "- lr: 0.01, **0.05**, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.250 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.3653973791306335\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.3649790781919959\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5018235344365239\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5016364496991038\n",
      "[proc 0][Train](20000/100000) average loss: 0.433401306335628\n",
      "[proc 0][Train](20000/100000) average regularization: 0.06240653116793717\n",
      "[proc 1][Train](20000/100000) average loss: 0.4335169144392014\n",
      "[proc 0][Train] 20000 steps take 530.993 seconds\n",
      "[proc 0]sample: 73.309, forward: 250.960, backward: 71.245, update: 131.191\n",
      "[proc 1][Train](20000/100000) average regularization: 0.062410781097342716\n",
      "[proc 1][Train] 20000 steps take 530.998 seconds\n",
      "[proc 1]sample: 71.163, forward: 256.897, backward: 70.925, update: 113.885\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.3267250902816653\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.32674441543370486\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.46845632624179123\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.468545317658782\n",
      "[proc 0][Train](40000/100000) average loss: 0.39764486657083037\n",
      "[proc 1][Train](40000/100000) average loss: 0.39759070832282306\n",
      "[proc 0][Train](40000/100000) average regularization: 0.06451207848377526\n",
      "[proc 1][Train](40000/100000) average regularization: 0.0645112310897559\n",
      "[proc 0][Train] 20000 steps take 506.861 seconds\n",
      "[proc 0]sample: 71.733, forward: 235.057, backward: 68.451, update: 122.282\n",
      "[proc 1][Train] 20000 steps take 506.852 seconds\n",
      "[proc 1]sample: 71.974, forward: 244.833, backward: 70.612, update: 114.453\n",
      "[0]Valid average MRR: 0.4199170175747901\n",
      "[0]Valid average MR: 69.75020768644114\n",
      "[0]Valid average HITS@1: 0.29451980171051917\n",
      "[0]Valid average HITS@3: 0.48702470447240837\n",
      "[0]Valid average HITS@10: 0.6592410252219861\n",
      "[proc 0]validation take 411.254 seconds:\n",
      "[1]Valid average MRR: 0.42093727679187715\n",
      "[1]Valid average MR: 68.7255493439196\n",
      "[1]Valid average HITS@1: 0.29522596811864604\n",
      "[1]Valid average HITS@3: 0.4882028095358069\n",
      "[1]Valid average HITS@10: 0.6596723343116092\n",
      "[proc 1]validation take 417.827 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.31637706734240056\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.3164257918089628\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.4578164937153459\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.45770099889487026\n",
      "[proc 1][Train](60000/100000) average loss: 0.38709678051918744\n",
      "[proc 0][Train](60000/100000) average loss: 0.3870633954927325\n",
      "[proc 1][Train](60000/100000) average regularization: 0.06483935998305679\n",
      "[proc 0][Train](60000/100000) average regularization: 0.06484107480235397\n",
      "[proc 1][Train] 20000 steps take 914.262 seconds\n",
      "[proc 1]sample: 69.706, forward: 241.171, backward: 69.115, update: 113.850\n",
      "[proc 0][Train] 20000 steps take 914.264 seconds\n",
      "[proc 0]sample: 70.274, forward: 234.761, backward: 67.267, update: 117.616\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.31099413615167143\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.31100449977368116\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.451473423050344\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.45169334923923016\n",
      "[proc 0][Train](80000/100000) average loss: 0.3812389613032341\n",
      "[proc 1][Train](80000/100000) average loss: 0.3813437427148223\n",
      "[proc 0][Train](80000/100000) average regularization: 0.06482563958726824\n",
      "[proc 0][Train] 20000 steps take 506.857 seconds\n",
      "[proc 0]sample: 71.660, forward: 236.248, backward: 68.548, update: 119.727\n",
      "[proc 1][Train](80000/100000) average regularization: 0.06482554659917951\n",
      "[proc 1][Train] 20000 steps take 506.864 seconds\n",
      "[proc 1]sample: 70.927, forward: 248.931, backward: 71.421, update: 110.797\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.30762601223140956\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.3076133187755942\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.4475930730342865\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.447560034391284\n",
      "[proc 0][Train](100000/100000) average loss: 0.3776095427274704\n",
      "[proc 0][Train](100000/100000) average regularization: 0.0646980934318155\n",
      "[proc 1][Train](100000/100000) average loss: 0.3775866764843464\n",
      "[proc 0][Train] 20000 steps take 535.775 seconds\n",
      "[proc 0]sample: 69.397, forward: 231.659, backward: 68.147, update: 129.006\n",
      "[proc 1][Train](100000/100000) average regularization: 0.06469843461588025\n",
      "[proc 1][Train] 20000 steps take 535.773 seconds\n",
      "[proc 1]sample: 68.026, forward: 243.441, backward: 71.131, update: 131.792\n",
      "[0]Valid average MRR: 0.43153780042703227\n",
      "[0]Valid average MR: 64.09098028000219\n",
      "[0]Valid average HITS@1: 0.29941915890396037\n",
      "[0]Valid average HITS@3: 0.5064859454159176\n",
      "[0]Valid average HITS@10: 0.6819197036552813\n",
      "[proc 0]validation take 389.274 seconds:\n",
      "[1]Valid average MRR: 0.43203328532534274\n",
      "[1]Valid average MR: 63.40704222474925\n",
      "[1]Valid average HITS@1: 0.29961799573734993\n",
      "[1]Valid average HITS@3: 0.5076332759078559\n",
      "[1]Valid average HITS@10: 0.6828513451861334\n",
      "[proc 1]validation take 391.644 seconds:\n",
      "proc 1 takes 3386.394 seconds\n",
      "proc 0 takes 3386.398 seconds\n",
      "training takes 3386.9443678855896 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_13\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.43056923806971364\n",
      "Test average MR : 64.827149880496\n",
      "Test average HITS@1 : 0.2984467883723622\n",
      "Test average HITS@3 : 0.505719849922033\n",
      "Test average HITS@10 : 0.6805276561553075\n",
      "-----------------------------------------\n",
      "testing takes 419.020 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 12.0 --lr 0.05 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 15\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: 6, **12**, 18\n",
    "\n",
    "- lr: 0.01, 0.05, **0.1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.394 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.3340937774641764\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.33458833409943883\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.47442354820370675\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.4755329421311617\n",
      "[proc 1][Train](20000/100000) average loss: 0.4042586628288031\n",
      "[proc 0][Train](20000/100000) average loss: 0.4050606382161379\n",
      "[proc 1][Train](20000/100000) average regularization: 0.06458057133642844\n",
      "[proc 0][Train](20000/100000) average regularization: 0.06457817973643659\n",
      "[proc 1][Train] 20000 steps take 536.637 seconds\n",
      "[proc 1]sample: 71.489, forward: 260.914, backward: 72.575, update: 129.415\n",
      "[proc 0][Train] 20000 steps take 536.646 seconds\n",
      "[proc 0]sample: 70.666, forward: 261.034, backward: 72.424, update: 130.764\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3031565735772252\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.30304316409826276\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.442408626934886\n",
      "[proc 0][Train](40000/100000) average loss: 0.37278260013759135\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.44236038580834863\n",
      "[proc 0][Train](40000/100000) average regularization: 0.06470529870763421\n",
      "[proc 0][Train] 20000 steps take 502.518 seconds\n",
      "[proc 0]sample: 71.391, forward: 237.057, backward: 68.137, update: 122.133\n",
      "[proc 1][Train](40000/100000) average loss: 0.3727017749130726\n",
      "[proc 1][Train](40000/100000) average regularization: 0.0646985395975411\n",
      "[proc 1][Train] 20000 steps take 502.533 seconds\n",
      "[proc 1]sample: 69.381, forward: 232.712, backward: 71.421, update: 122.748\n",
      "[0]Valid average MRR: 0.4347290480315882\n",
      "[0]Valid average MR: 62.25828362477529\n",
      "[0]Valid average HITS@1: 0.30055973198235003\n",
      "[0]Valid average HITS@3: 0.5114227542626791\n",
      "[0]Valid average HITS@10: 0.6880447513210219\n",
      "[proc 0]validation take 400.300 seconds:\n",
      "[1]Valid average MRR: 0.4355810371397161\n",
      "[1]Valid average MR: 61.21765731289622\n",
      "[1]Valid average HITS@1: 0.3014803516345833\n",
      "[1]Valid average HITS@3: 0.5125121717044472\n",
      "[1]Valid average HITS@10: 0.6885882184710297\n",
      "[proc 1]validation take 410.096 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.29930595329403875\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.2992339537769556\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.4374022960722446\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.43743486282378435\n",
      "[proc 0][Train](60000/100000) average loss: 0.36835412463843825\n",
      "[proc 1][Train](60000/100000) average loss: 0.36833440832346676\n",
      "[proc 0][Train](60000/100000) average regularization: 0.06415117639116943\n",
      "[proc 1][Train](60000/100000) average regularization: 0.06414486519619822\n",
      "[proc 0][Train] 20000 steps take 919.799 seconds\n",
      "[proc 0]sample: 69.496, forward: 245.490, backward: 69.742, update: 123.956\n",
      "[proc 1][Train] 20000 steps take 919.790 seconds\n",
      "[proc 1]sample: 69.342, forward: 237.646, backward: 68.207, update: 127.679\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.29760391197353603\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.29752499296963214\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4351713889449835\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4350714023500681\n",
      "[proc 0][Train](80000/100000) average loss: 0.36638765049129723\n",
      "[proc 1][Train](80000/100000) average loss: 0.36629819766581057\n",
      "[proc 0][Train](80000/100000) average regularization: 0.06380629998929799\n",
      "[proc 1][Train](80000/100000) average regularization: 0.06380117342993617\n",
      "[proc 0][Train] 20000 steps take 507.852 seconds\n",
      "[proc 0]sample: 67.070, forward: 247.910, backward: 70.411, update: 122.194\n",
      "[proc 1][Train] 20000 steps take 507.851 seconds\n",
      "[proc 1]sample: 69.342, forward: 232.699, backward: 67.845, update: 129.663\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.2965538717225194\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.2966329169809818\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.433782117767632\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.4338497655376792\n",
      "[proc 1][Train](100000/100000) average loss: 0.3651679946452379\n",
      "[proc 0][Train](100000/100000) average loss: 0.36524134130477903\n",
      "[proc 1][Train](100000/100000) average regularization: 0.06356969481594861\n",
      "[proc 1][Train] 20000 steps take 506.420 seconds\n",
      "[proc 1]sample: 69.043, forward: 233.357, backward: 68.101, update: 126.667\n",
      "[proc 0][Train](100000/100000) average regularization: 0.06357395055294036\n",
      "[proc 0][Train] 20000 steps take 506.424 seconds\n",
      "[proc 0]sample: 66.778, forward: 247.643, backward: 70.054, update: 121.677\n",
      "[0]Valid average MRR: 0.43720292675679395\n",
      "[0]Valid average MR: 60.55879569101705\n",
      "[0]Valid average HITS@1: 0.30186373045704634\n",
      "[0]Valid average HITS@3: 0.5154028436018957\n",
      "[0]Valid average HITS@10: 0.6927125892030288\n",
      "[proc 0]validation take 385.734 seconds:\n",
      "[1]Valid average MRR: 0.43882771726763714\n",
      "[1]Valid average MR: 59.55881571869234\n",
      "[1]Valid average HITS@1: 0.30384659907256717\n",
      "[1]Valid average HITS@3: 0.5163696657292468\n",
      "[1]Valid average HITS@10: 0.6943659478267975\n",
      "[proc 1]validation take 396.334 seconds:\n",
      "proc 1 takes 3369.567 seconds\n",
      "proc 0 takes 3369.572 seconds\n",
      "training takes 3370.0556604862213 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_14\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.43722459698865124\n",
      "Test average MR : 60.83355236726884\n",
      "Test average HITS@1 : 0.3020931926976583\n",
      "Test average HITS@3 : 0.5153057055502972\n",
      "Test average HITS@10 : 0.6925784947261622\n",
      "-----------------------------------------\n",
      "testing takes 409.638 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 12.0 --lr 0.1 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 16\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: 6, 12, **18**\n",
    "\n",
    "- lr: **0.01**, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.276 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.5380992512675365\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.5477685262475245\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.6103035657078028\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.6077735254883766\n",
      "[proc 1][Train](20000/100000) average loss: 0.5742014084026218\n",
      "[proc 1][Train](20000/100000) average regularization: 4.133108589709015\n",
      "[proc 0][Train](20000/100000) average loss: 0.577771025814116\n",
      "[proc 1][Train] 20000 steps take 529.066 seconds\n",
      "[proc 1]sample: 70.204, forward: 256.355, backward: 70.175, update: 129.194\n",
      "[proc 0][Train](20000/100000) average regularization: 4.548002031047763\n",
      "[proc 0][Train] 20000 steps take 529.085 seconds\n",
      "[proc 0]sample: 69.173, forward: 253.349, backward: 69.507, update: 130.360\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.4775803399696946\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.468670797765255\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.5569677086442709\n",
      "[proc 0][Train](40000/100000) average loss: 0.5172740242898464\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.5569504750326276\n",
      "[proc 0][Train](40000/100000) average regularization: 4.384187692071498\n",
      "[proc 0][Train] 20000 steps take 531.123 seconds\n",
      "[proc 0]sample: 70.417, forward: 261.935, backward: 70.507, update: 127.944\n",
      "[proc 1][Train](40000/100000) average loss: 0.5128106363430619\n",
      "[proc 1][Train](40000/100000) average regularization: 3.9570168368369343\n",
      "[proc 1][Train] 20000 steps take 531.149 seconds\n",
      "[proc 1]sample: 70.168, forward: 251.732, backward: 69.814, update: 128.594\n",
      "[0]Valid average MRR: 0.17737029293139597\n",
      "[0]Valid average MR: 240.67065016070163\n",
      "[0]Valid average HITS@1: 0.10739431824372174\n",
      "[0]Valid average HITS@3: 0.19380209184507272\n",
      "[0]Valid average HITS@10: 0.30469643732636054\n",
      "[proc 0]validation take 353.979 seconds:\n",
      "[1]Valid average MRR: 0.17869132405916022\n",
      "[1]Valid average MR: 239.01770429737772\n",
      "[1]Valid average HITS@1: 0.10874524197007973\n",
      "[1]Valid average HITS@3: 0.19493452814642817\n",
      "[1]Valid average HITS@10: 0.3057191689875185\n",
      "[proc 1]validation take 394.526 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.4562709992006421\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.4653151990249753\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.5533464516013861\n",
      "[proc 0][Train](60000/100000) average loss: 0.5093308253392577\n",
      "[proc 0][Train](60000/100000) average regularization: 4.211115456532687\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.5534326214790344\n",
      "[proc 0][Train] 20000 steps take 907.330 seconds\n",
      "[proc 0]sample: 67.813, forward: 249.806, backward: 67.741, update: 118.867\n",
      "[proc 1][Train](60000/100000) average loss: 0.5048518102049827\n",
      "[proc 1][Train](60000/100000) average regularization: 3.794499052555114\n",
      "[proc 1][Train] 20000 steps take 907.329 seconds\n",
      "[proc 1]sample: 67.956, forward: 253.420, backward: 69.655, update: 120.756\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.4610467847630382\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.4517511945679784\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.551990984493494\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.5520555241391063\n",
      "[proc 0][Train](80000/100000) average loss: 0.5065188845962286\n",
      "[proc 0][Train](80000/100000) average regularization: 4.151111933368444\n",
      "[proc 1][Train](80000/100000) average loss: 0.5019033593937755\n",
      "[proc 0][Train] 20000 steps take 491.108 seconds\n",
      "[proc 0]sample: 66.344, forward: 241.379, backward: 67.643, update: 110.872\n",
      "[proc 1][Train](80000/100000) average regularization: 3.7262126763910057\n",
      "[proc 1][Train] 20000 steps take 491.097 seconds\n",
      "[proc 1]sample: 67.412, forward: 245.262, backward: 68.685, update: 109.163\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.4554062183395028\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.44643062366992237\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.5477727873176337\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.5478585758388043\n",
      "[proc 0][Train](100000/100000) average loss: 0.5015895028218627\n",
      "[proc 0][Train](100000/100000) average regularization: 4.12604819881171\n",
      "[proc 1][Train](100000/100000) average loss: 0.4971445995494723\n",
      "[proc 0][Train] 20000 steps take 492.284 seconds\n",
      "[proc 0]sample: 66.108, forward: 244.167, backward: 67.907, update: 109.882\n",
      "[proc 1][Train](100000/100000) average regularization: 3.647190420129895\n",
      "[proc 1][Train] 20000 steps take 492.284 seconds\n",
      "[proc 1]sample: 67.251, forward: 246.284, backward: 68.938, update: 108.462\n",
      "[0]Valid average MRR: 0.21547286845364044\n",
      "[0]Valid average MR: 205.91741910442883\n",
      "[0]Valid average HITS@1: 0.1372500953314812\n",
      "[0]Valid average HITS@3: 0.23613948357574768\n",
      "[0]Valid average HITS@10: 0.36113948357574766\n",
      "[proc 0]validation take 354.529 seconds:\n",
      "[1]Valid average MRR: 0.21656561726517387\n",
      "[1]Valid average MR: 203.94086083741325\n",
      "[1]Valid average HITS@1: 0.13807649618336204\n",
      "[1]Valid average HITS@3: 0.23796278011943592\n",
      "[1]Valid average HITS@10: 0.3623593019059357\n",
      "[proc 1]validation take 374.629 seconds:\n",
      "proc 1 takes 3325.554 seconds\n",
      "proc 0 takes 3325.564 seconds\n",
      "training takes 3326.036806344986 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_15\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.2164509922332917\n",
      "Test average MR : 207.1971033045752\n",
      "Test average HITS@1 : 0.13827907420143404\n",
      "Test average HITS@3 : 0.23785553293339778\n",
      "Test average HITS@10 : 0.36177199588715553\n",
      "-----------------------------------------\n",
      "testing takes 365.884 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 18.0 --lr 0.01 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 17\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: 6, 12, **18**\n",
    "\n",
    "- lr: 0.01, **0.05**, 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.392 seconds\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.36699601338713167\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.3680561326464884\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5296644154727459\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.530770330786705\n",
      "[proc 1][Train](20000/100000) average loss: 0.4483302145138383\n",
      "[proc 0][Train](20000/100000) average loss: 0.4494132317379117\n",
      "[proc 1][Train](20000/100000) average regularization: 0.15112371032740904\n",
      "[proc 0][Train](20000/100000) average regularization: 0.15113956211154672\n",
      "[proc 1][Train] 20000 steps take 660.451 seconds\n",
      "[proc 1]sample: 71.453, forward: 246.558, backward: 74.514, update: 266.262\n",
      "[proc 0][Train] 20000 steps take 660.484 seconds\n",
      "[proc 0]sample: 69.089, forward: 252.321, backward: 73.528, update: 219.669\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.3199691659644246\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.32020858209729197\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.489749948348105\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.48999949979037044\n",
      "[proc 0][Train](40000/100000) average loss: 0.4048595571383834\n",
      "[proc 0][Train](40000/100000) average regularization: 0.14771137887462973\n",
      "[proc 1][Train](40000/100000) average loss: 0.4051040409117937\n",
      "[proc 0][Train] 20000 steps take 674.956 seconds\n",
      "[proc 0]sample: 69.243, forward: 248.543, backward: 74.236, update: 272.278\n",
      "[proc 1][Train](40000/100000) average regularization: 0.14769433773308993\n",
      "[proc 1][Train] 20000 steps take 674.969 seconds\n",
      "[proc 1]sample: 71.986, forward: 243.498, backward: 74.474, update: 284.674\n",
      "[1]Valid average MRR: 0.3805855361235332\n",
      "[1]Valid average MR: 83.98892800479378\n",
      "[1]Valid average HITS@1: 0.26334461414845733\n",
      "[1]Valid average HITS@3: 0.43361569417869084\n",
      "[1]Valid average HITS@10: 0.6107369754250733\n",
      "[proc 1]validation take 392.657 seconds:\n",
      "[0]Valid average MRR: 0.3795647710407422\n",
      "[0]Valid average MR: 85.55057335076538\n",
      "[0]Valid average HITS@1: 0.26233180802963446\n",
      "[0]Valid average HITS@3: 0.432866209075557\n",
      "[0]Valid average HITS@10: 0.6113675981914256\n",
      "[proc 0]validation take 396.577 seconds:\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.30654104095846413\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.30634610035419463\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.4782523633435369\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.4781094221651554\n",
      "[proc 1][Train](60000/100000) average loss: 0.39239670210033656\n",
      "[proc 1][Train](60000/100000) average regularization: 0.14591162653341888\n",
      "[proc 0][Train](60000/100000) average loss: 0.39222776128053666\n",
      "[proc 1][Train] 20000 steps take 1044.135 seconds\n",
      "[proc 1]sample: 67.330, forward: 237.647, backward: 69.449, update: 130.772\n",
      "[proc 0][Train](60000/100000) average regularization: 0.14592415856793522\n",
      "[proc 0][Train] 20000 steps take 1044.157 seconds\n",
      "[proc 0]sample: 69.653, forward: 236.052, backward: 74.331, update: 266.555\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.29877069839686154\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.29846910222917794\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4710383872285485\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4709190542384982\n",
      "[proc 1][Train](80000/100000) average loss: 0.38490454276055097\n",
      "[proc 1][Train](80000/100000) average regularization: 0.14490566906780006\n",
      "[proc 0][Train](80000/100000) average loss: 0.3846940782010555\n",
      "[proc 1][Train] 20000 steps take 510.022 seconds\n",
      "[proc 1]sample: 71.037, forward: 248.017, backward: 71.802, update: 116.854\n",
      "[proc 0][Train](80000/100000) average regularization: 0.1449266612507403\n",
      "[proc 0][Train] 20000 steps take 510.017 seconds\n",
      "[proc 0]sample: 69.868, forward: 234.224, backward: 67.976, update: 119.974\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.29344042776077983\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.293192946305871\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.4656877427980304\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.46607151421010495\n",
      "[proc 0][Train](100000/100000) average loss: 0.37944034467041493\n",
      "[proc 1][Train](100000/100000) average loss: 0.3797559709891677\n",
      "[proc 0][Train](100000/100000) average regularization: 0.14421194632202386\n",
      "[proc 1][Train](100000/100000) average regularization: 0.14419292412027718\n",
      "[proc 0][Train] 20000 steps take 507.532 seconds\n",
      "[proc 0]sample: 69.981, forward: 239.261, backward: 67.016, update: 119.721\n",
      "[proc 1][Train] 20000 steps take 507.541 seconds\n",
      "[proc 1]sample: 70.556, forward: 246.810, backward: 69.790, update: 119.658\n",
      "[0]Valid average MRR: 0.39067502956758654\n",
      "[0]Valid average MR: 75.11485060195021\n",
      "[0]Valid average HITS@1: 0.2609426921610285\n",
      "[0]Valid average HITS@3: 0.4543770768644114\n",
      "[0]Valid average HITS@10: 0.6487205153347497\n",
      "[proc 0]validation take 365.359 seconds:\n",
      "[1]Valid average MRR: 0.3916976274407525\n",
      "[1]Valid average MR: 73.9917130269582\n",
      "[1]Valid average HITS@1: 0.26221766752691394\n",
      "[1]Valid average HITS@3: 0.45485063701423833\n",
      "[1]Valid average HITS@10: 0.650299270719135\n",
      "[proc 1]validation take 368.218 seconds:\n",
      "proc 1 takes 3765.336 seconds\n",
      "proc 0 takes 3765.366 seconds\n",
      "training takes 3765.8633897304535 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_16\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.39014313196279454\n",
      "Test average MR : 76.20149873686647\n",
      "Test average HITS@1 : 0.2607621700021109\n",
      "Test average HITS@3 : 0.45318575212621803\n",
      "Test average HITS@10 : 0.6481441129806547\n",
      "-----------------------------------------\n",
      "testing takes 405.199 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 18.0 --lr 0.05 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 18\n",
    "\n",
    "- batch_size: **4096**\n",
    "\n",
    "- neg_sample_size: **256**\n",
    "\n",
    "- hidden_dim: 200, **400**\n",
    "\n",
    "- gamma: 6, 12, **18**\n",
    "\n",
    "- lr: 0.01, 0.05, **0.1**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading train triples....\n",
      "Finished. Read 5286834 train triples.\n",
      "Reading valid triples....\n",
      "Finished. Read 293713 valid triples.\n",
      "Reading test triples....\n",
      "Finished. Read 293714 test triples.\n",
      "|Train|: 5286834\n",
      "random partition 5286834 edges into 2 parts\n",
      "part 0 has 2643417 edges\n",
      "part 1 has 2643417 edges\n",
      "/home/luyanfeng/miniconda3/envs/drkg/lib/python3.8/site-packages/dgl/base.py:25: UserWarning: multigraph will be deprecated.DGL will treat all graphs as multigraph in the future.\n",
      "  warnings.warn(msg, warn_type)\n",
      "|valid|: 293713\n",
      "|test|: 293714\n",
      "Total initialize time 16.370 seconds\n",
      "[proc 0][Train](20000/100000) average pos_loss: 0.33608534073143187\n",
      "[proc 1][Train](20000/100000) average pos_loss: 0.3353845762288461\n",
      "[proc 0][Train](20000/100000) average neg_loss: 0.5065470913350583\n",
      "[proc 0][Train](20000/100000) average loss: 0.42131621600985525\n",
      "[proc 0][Train](20000/100000) average regularization: 0.14727456246098872\n",
      "[proc 1][Train](20000/100000) average neg_loss: 0.5054075894802809\n",
      "[proc 0][Train] 20000 steps take 530.858 seconds\n",
      "[proc 0]sample: 69.790, forward: 251.429, backward: 75.516, update: 131.493\n",
      "[proc 1][Train](20000/100000) average loss: 0.4203960829690099\n",
      "[proc 1][Train](20000/100000) average regularization: 0.1472866921055388\n",
      "[proc 1][Train] 20000 steps take 530.871 seconds\n",
      "[proc 1]sample: 71.096, forward: 250.681, backward: 73.060, update: 130.076\n",
      "[proc 1][Train](40000/100000) average pos_loss: 0.2890547496512532\n",
      "[proc 1][Train](40000/100000) average neg_loss: 0.4612879116907716\n",
      "[proc 0][Train](40000/100000) average pos_loss: 0.28915457151979207\n",
      "[proc 1][Train](40000/100000) average loss: 0.37517133069485425\n",
      "[proc 1][Train](40000/100000) average regularization: 0.14319464449882507\n",
      "[proc 0][Train](40000/100000) average neg_loss: 0.4614548760995269\n",
      "[proc 1][Train] 20000 steps take 526.084 seconds\n",
      "[proc 1]sample: 70.276, forward: 248.682, backward: 71.797, update: 125.155\n",
      "[proc 0][Train](40000/100000) average loss: 0.3753047237575054\n",
      "[proc 0][Train](40000/100000) average regularization: 0.14316246846318245\n",
      "[proc 0][Train] 20000 steps take 526.119 seconds\n",
      "[proc 0]sample: 71.034, forward: 249.724, backward: 76.266, update: 126.870\n",
      "[1]Valid average MRR: 0.3944924335597845\n",
      "[1]Valid average MR: 72.12433183300762\n",
      "[1]Valid average HITS@1: 0.260106770531878\n",
      "[1]Valid average HITS@3: 0.4612548261233717\n",
      "[1]Valid average HITS@10: 0.6639656264257067\n",
      "[proc 1]validation take 406.123 seconds:\n",
      "[0]Valid average MRR: 0.3928935451265156\n",
      "[0]Valid average MR: 72.79337922863213\n",
      "[0]Valid average HITS@1: 0.25792272702511304\n",
      "[0]Valid average HITS@3: 0.4606825734052405\n",
      "[0]Valid average HITS@10: 0.6627410524595522\n",
      "[proc 0]validation take 410.464 seconds:\n",
      "[proc 0][Train](60000/100000) average pos_loss: 0.280747599811852\n",
      "[proc 1][Train](60000/100000) average pos_loss: 0.28066384523957966\n",
      "[proc 1][Train](60000/100000) average neg_loss: 0.452185158264637\n",
      "[proc 0][Train](60000/100000) average neg_loss: 0.45251270434558394\n",
      "[proc 1][Train](60000/100000) average loss: 0.3664245016902685\n",
      "[proc 0][Train](60000/100000) average loss: 0.3666301520392299\n",
      "[proc 1][Train](60000/100000) average regularization: 0.14185357148870825\n",
      "[proc 0][Train](60000/100000) average regularization: 0.14181687631979584\n",
      "[proc 1][Train] 20000 steps take 931.478 seconds\n",
      "[proc 1]sample: 69.143, forward: 248.040, backward: 72.148, update: 123.159\n",
      "[proc 0][Train] 20000 steps take 931.467 seconds\n",
      "[proc 0]sample: 69.020, forward: 247.265, backward: 74.959, update: 128.357\n",
      "[proc 0][Train](80000/100000) average pos_loss: 0.2770418817698955\n",
      "[proc 1][Train](80000/100000) average pos_loss: 0.2769525295883417\n",
      "[proc 0][Train](80000/100000) average neg_loss: 0.4480636001974344\n",
      "[proc 1][Train](80000/100000) average neg_loss: 0.4478873888462782\n",
      "[proc 0][Train](80000/100000) average loss: 0.3625527409777045\n",
      "[proc 1][Train](80000/100000) average loss: 0.3624199592217803\n",
      "[proc 0][Train](80000/100000) average regularization: 0.14105935761034488\n",
      "[proc 1][Train](80000/100000) average regularization: 0.1410934280477464\n",
      "[proc 0][Train] 20000 steps take 511.662 seconds\n",
      "[proc 0]sample: 69.118, forward: 241.969, backward: 75.328, update: 124.919\n",
      "[proc 1][Train] 20000 steps take 511.664 seconds\n",
      "[proc 1]sample: 67.633, forward: 236.992, backward: 70.060, update: 121.517\n",
      "[proc 1][Train](100000/100000) average pos_loss: 0.2747972672581673\n",
      "[proc 0][Train](100000/100000) average pos_loss: 0.2748877684250474\n",
      "[proc 1][Train](100000/100000) average neg_loss: 0.4452956413730979\n",
      "[proc 0][Train](100000/100000) average neg_loss: 0.4453564771309495\n",
      "[proc 1][Train](100000/100000) average loss: 0.360046454320848\n",
      "[proc 1][Train](100000/100000) average regularization: 0.14058916480690242\n",
      "[proc 0][Train](100000/100000) average loss: 0.3601221228182316\n",
      "[proc 1][Train] 20000 steps take 511.803 seconds\n",
      "[proc 1]sample: 67.343, forward: 235.445, backward: 70.382, update: 121.653\n",
      "[proc 0][Train](100000/100000) average regularization: 0.14055623239576817\n",
      "[proc 0][Train] 20000 steps take 511.808 seconds\n",
      "[proc 0]sample: 68.834, forward: 242.832, backward: 75.385, update: 124.420\n",
      "[0]Valid average MRR: 0.3962854144830095\n",
      "[0]Valid average MR: 70.73069537506129\n",
      "[0]Valid average HITS@1: 0.25975445334204933\n",
      "[0]Valid average HITS@3: 0.46458095004630384\n",
      "[0]Valid average HITS@10: 0.6706297325271013\n",
      "[proc 0]validation take 405.767 seconds:\n",
      "[1]Valid average MRR: 0.3971110873826839\n",
      "[1]Valid average MR: 69.95326405959538\n",
      "[1]Valid average HITS@1: 0.2601646499656128\n",
      "[1]Valid average HITS@3: 0.4664775938497995\n",
      "[1]Valid average HITS@10: 0.6711188435008205\n",
      "[proc 1]validation take 412.658 seconds:\n",
      "proc 1 takes 3424.558 seconds\n",
      "proc 0 takes 3424.570 seconds\n",
      "training takes 3425.1154346466064 seconds\n",
      "Save model to ckpts/TransE_l2_DRKG_17\n",
      "-------------- Test result --------------\n",
      "Test average MRR : 0.39611510452120885\n",
      "Test average MR : 71.99841682725372\n",
      "Test average HITS@1 : 0.25985993177036165\n",
      "Test average HITS@3 : 0.4643769108724814\n",
      "Test average HITS@10 : 0.6696531319582996\n",
      "-----------------------------------------\n",
      "testing takes 403.663 seconds\n"
     ]
    }
   ],
   "source": [
    "!DGLBACKEND=pytorch dglke_train --dataset DRKG --data_path ./dataset \\\n",
    "--data_files drkg_train.tsv drkg_valid.tsv drkg_test.tsv --format 'raw_udd_hrt' \\\n",
    "--model_name TransE_l2 \\\n",
    "--batch_size 4096 --neg_sample_size 256 --hidden_dim 400 \\\n",
    "--gamma 18.0 --lr 0.1 --max_step 100000 -adv --regularization_coef 1.00E-07 \\\n",
    "--gpu 0 1 --num_proc 2 --mix_cpu_gpu --async_update --force_sync_interval 1000 \\\n",
    "--valid --test \\\n",
    "--batch_size_eval 128 --neg_sample_size_eval 10000 \\\n",
    "--log_interval 20000 --eval_interval 50000 --num_thread 32"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  },
  "vscode": {
   "interpreter": {
    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
